Issue with setting enumeration flags in VB.NET for Faster WMI queries

By travis.myers ·

I have been combing the net looking for information regarding how to use WMI to query event logs on remote hosts. I'm having the common problem of logs taking a long time to enumerate and stumbled upon information about the appropriate flags to set on the query but I'm struggling to translate the following bit of code to friendly terms:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NTLogEvent",,4
For Each objItem in colItems
Wscript.Echo "Category: " & objItem.Category
Wscript.Echo "ComputerName: " & objItem.ComputerName
Wscript.Echo "EventCode: " & objItem.EventCode
Wscript.Echo "Message: " & objItem.Message
Wscript.Echo "TimeWritten: " & objItem.TimeWritten
Wscript.Echo "Type: " & objItem.Type

I understand how to convert this VBS code to code except for the specifiying of the wbemFlagReturnImmediately + wbemFlagForwardOnly flags. I can not, for the life of me, figure out how to specify these flags properly in code.

In a nutshell I cant figure out where to place the ,,48 integer value associated with those two flags.
Here is the code from the WMI code creator:

Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NTLogEvent")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("Win32_NTLogEvent instance")
Console.WriteLine("Category: {0}", queryObj("Category"))
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace

Can anyone help me take this cookie cutter code and apply the appropriate semisych flags so I can speed up these remote queries?

thanks in advance.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Related Discussions

Related Forums