PC Review
Forums
Newsgroups
Windows XP
Windows XP WMI
Speeding up reading Eventlog
Forums
Newsgroups
Windows XP
Windows XP WMI
Speeding up reading Eventlog
![]() |
Speeding up reading Eventlog |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi, I'm using wmi to read the event log. After just a small number of
entries, it really slows down. I'd really like to speed it up. Any suggestions? Here's a code snippet: 'Connect to WMI using the current user's credentials Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\cimv2") ' 'Query WMI for all 539 errors in the event log 'Note: This takes a long time on big event logs wscript.echo "Retrieving records from the Security Log." Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent Where Logfile = 'Security' and EventCode = '539'") ' 'For all the Event records with 539 errors... For Each objEvent in colLoggedEvents ' 'do stuff Next -- ======================================================= David Johnson, MCP, MCSE, MCSD, MCDBA <a href = "http://www.azletexas.net">High speed internet for Azle</a> |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Since by default the enumerator is bidirectional which requires WMI to cache
each object, large numbers of objects will slow the query down. This can be altered using the flags wbemFlagForwardOnly and wbemFlagReturnImmediately when you ExecQuery. Here's a snippet to get you going. wbemFlagReturnImmediately = 16 wbemFlagForwardOnly = 32 IFlags = wbemFlagReturnImmediately + wbemFlagForwardOnly wscript.echo semisynchronousflags set objWMIService = GetObject("winmgmts:root\cimv2") ' Query for all the Win32_Process objects on the ' local machine and use forward-only enumerator set colProcesses = objWMIService.ExecQuery_ ("SELECT Name FROM Win32_Process",,IFlags) ' Receive each object as it arrives For Each objProcess in colProcesses WScript.Echo objProcess.name Next -- Philip Nunn [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm. "David Johnson" <djohnson@i2.com> wrote in message news:uTaJS$DjEHA.2448@TK2MSFTNGP12.phx.gbl... > Hi, I'm using wmi to read the event log. After just a small number of > entries, it really slows down. I'd really like to speed it up. > > Any suggestions? > > Here's a code snippet: > > 'Connect to WMI using the current user's credentials > Set objWMIService = > GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & > strComputer & "\root\cimv2") > ' > 'Query WMI for all 539 errors in the event log > 'Note: This takes a long time on big event logs > wscript.echo "Retrieving records from the Security Log." > Set colLoggedEvents = objWMIService.ExecQuery _ > ("Select * from Win32_NTLogEvent Where Logfile = 'Security' and EventCode > = > '539'") > ' > 'For all the Event records with 539 errors... > For Each objEvent in colLoggedEvents > ' > 'do stuff > Next > > -- > ======================================================= > David Johnson, MCP, MCSE, MCSD, MCDBA > <a href = "http://www.azletexas.net">High speed internet for Azle</a> > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

