Using ManagementEventWatcher and Win32_NTLogEvent

R

Rob

Hello.

I'm attempting to write a VB.NET application to monitor events they are
written to the Windows event logs.

I have the following code, but it fails at the Start method, throwing an
'Access Denied' exception. This is being run under the administrator
account:

'Initialize an event watcher object with this query
Dim watcher As New ManagementEventWatcher(New
WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA
'Win32_NTLogEvent'"))
'Set up a handler for incoming events
Dim handler As New MyHandler()

AddHandler watcher.EventArrived, AddressOf handler.Arrived

'Start watching for events
watcher.Start() 'CODE FAILS HERE

'loop to wait for an event to arrive.
While Not handler.IsArrived
Console.Write("0")
System.Threading.Thread.Sleep(1000)
End While

'only wait for one event, so stop watching
watcher.Stop()

Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top