G
Guest
I suspect that several others have seem the same program but here goes:
I have sets of code (C# and VB.Net) that both show the same problem.
Basically, the call to "ManagementEventWatcher.Start" fails with an access
denied since upgrading to SP1 for .Net 1.1 - the same code runs on non SP1
machines without a problem. Also, the code is basically the Microsoft
example code.
I have seen notes regarding STAThread and MTAThread, etc. Non of this seems
to make a difference. Has anyone got any more adviice/details?
Thanks,
Mark
Below is the VB.Net code (as the C# is still part of a larger program) -
console app calls GetEvents() - reference to the system.management.dll (the
new one from SP1)
--------------------------------------------------------------------------------------------
Imports System
Imports System.Management
' This example demonstrates how to subscribe an event using the
ManagementEventWatcher object.
Class Sample
Public Shared Sub GetEvents()
Dim sc As ManagementScope
Dim co As ConnectionOptions
co = New ConnectionOptions
co.Impersonation = ImpersonationLevel.Impersonate
co.EnablePrivileges = True
sc = New ManagementScope("\ROOT\CIMV2", co)
' Set up an event watcher and a handler for the event
Dim q As New WqlEventQuery("__InstanceCreationEvent",
"TargetInstance ISA 'Win32_NTLogEvent'")
Dim watcher As New ManagementEventWatcher(sc, q)
Dim handler As New MyHandler
AddHandler watcher.EventArrived, AddressOf handler.Arrived
' Start watching for events
watcher.Start()
System.Threading.Thread.Sleep(20000)
' Stop watching
watcher.Stop()
End Sub
End Class
Public Class MyHandler
Public Sub Arrived(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)
Console.WriteLine("OK")
End Sub
End Class
I have sets of code (C# and VB.Net) that both show the same problem.
Basically, the call to "ManagementEventWatcher.Start" fails with an access
denied since upgrading to SP1 for .Net 1.1 - the same code runs on non SP1
machines without a problem. Also, the code is basically the Microsoft
example code.
I have seen notes regarding STAThread and MTAThread, etc. Non of this seems
to make a difference. Has anyone got any more adviice/details?
Thanks,
Mark
Below is the VB.Net code (as the C# is still part of a larger program) -
console app calls GetEvents() - reference to the system.management.dll (the
new one from SP1)
--------------------------------------------------------------------------------------------
Imports System
Imports System.Management
' This example demonstrates how to subscribe an event using the
ManagementEventWatcher object.
Class Sample
Public Shared Sub GetEvents()
Dim sc As ManagementScope
Dim co As ConnectionOptions
co = New ConnectionOptions
co.Impersonation = ImpersonationLevel.Impersonate
co.EnablePrivileges = True
sc = New ManagementScope("\ROOT\CIMV2", co)
' Set up an event watcher and a handler for the event
Dim q As New WqlEventQuery("__InstanceCreationEvent",
"TargetInstance ISA 'Win32_NTLogEvent'")
Dim watcher As New ManagementEventWatcher(sc, q)
Dim handler As New MyHandler
AddHandler watcher.EventArrived, AddressOf handler.Arrived
' Start watching for events
watcher.Start()
System.Threading.Thread.Sleep(20000)
' Stop watching
watcher.Stop()
End Sub
End Class
Public Class MyHandler
Public Sub Arrived(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)
Console.WriteLine("OK")
End Sub
End Class