PC Review Forums Newsgroups Windows XP Windows XP WMI Speeding up reading Eventlog

Reply

Speeding up reading Eventlog

 
Thread Tools Rate Thread
Old 27-08-2004, 02:11 PM   #1
David Johnson
Guest
 
Posts: n/a
Default Speeding up reading Eventlog


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>


  Reply With Quote
Old 31-08-2004, 08:45 PM   #2
Philip Nunn [MSFT]
Guest
 
Posts: n/a
Default Re: Speeding up reading Eventlog

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>
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off