[python-win32] Backing up and clearing event logs

Tim Golden mail at timgolden.me.uk
Fri Jul 20 10:54:47 CEST 2007


Mårten Hedman wrote:
> Hello,
> 
> I am trying to write a script for backing up and clearing event logs on
> our Windows 2003 servers, using Python 2.5 and Tim Golden's WMI module.
> While testing with the Application log on a local Windows XP machine I
> seem to get stuck on the parameters to WMI.
> 
> The following code:
> 
> import wmi
> c = wmi.WMI(privileges=["Backup"])
> logfiles = c.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE
>   LogFileName='Application'")
> 
> for lf in logfiles:
>     lf.BackupEventLog("c:\\temp\\Applog.evt")
> 
> gives the following error message:
> 
> Traceback (most recent call last):
>    File "<interactive input>", line 2, in <module>
>    File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line
> 491, in __getattr__
>      raise pythoncom.com_error, details
> com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx',
> 'Invalid parameter ', None, 0, -2147217400), None)

I doubt if the moniker's got anything to do with it.
You're just falling foul of the fact that I haven't
released the fix which allows positional args in
a WMI method call: you have to use named args. So...

<dump>
 >>> import wmi
 >>> c = wmi.WMI ()
 >>> log = c.Win32_NTEventLogFile
 >>> print log.BackupEventlog
<function BackupEventlog (ArchiveFileName) => (ReturnValue) | Needs: SeSecurityPrivilege, SeBackupPrivilege>
 >>>

</dump>

... try:

lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah")

TJG


More information about the Python-win32 mailing list