
How to Retrieve Events For One Day From An Event Log on Windows 2000/NT
Quote:
> Thank you so much. It works. I would like to retrieve one day event logs in
> Asynchronous Event Log Query.
> That's combine both scripts. How to do it?
> Asynchronous Event Log Query
> Description
> Uses an asynchronous query to retrieve all the events recorded in all the
> event logs. This approach is faster than retrieving a large number of events
> using a synchronous query.
Hi
I suggest using a semisynchronous call adding the wbemFlagForwardOnly flag for
optimization. Combining wbemFlagReturnImmediately with wbemFlagForwardOnly
results in a forward-only enumerator. A forward-only enumerator performs much
faster than the default enumerator, because WMI doesn't maintain references to
objects in the SWbemObjectSet.
When using ExecQuery for large data sets on remote computers, you really *need*
this setting.
ExecQuery("Select ...", "WQL", 48) or ExecQuery("Select ...",, 48)
The WBEM_FLAG_FORWARD_ONLY combined with the WBEM_FLAG_RETURN_IMMEDIATELY flag
sums up to a decimal value of 48 in the iFlag argument in ExecQuery.
If you don't use it for large collections, you risk that the scripts will be dog
slow and in some cases grind to a halt all together. A snail will be quick in
comparison ;-)
Platform SDK: Windows Management Instrumentation
IWbemServices::ExecQuery
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/iwbemservices_exec...
Calling a Method
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/calling_a_method.asp
Making a Semisynchronous Call with VBScript
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/making_a_semisynch...
So, in the script I provided, change
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
to
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'",, 48)
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter