Question

Locked

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

By travis.myers ·
Hi,



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 VB.net friendly terms:



strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
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
Next


I understand how to convert this VBS code to VB.net 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 VB.net 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
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NTLogEvent")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_NTLogEvent instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Category: {0}", queryObj("Category"))
Next
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.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums