Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI - access denied

Status
Not open for further replies.

haddaway

Programmer
Jul 6, 2005
172
SE
I am trying to connect to a remote server and watch __instancecreationevent on processes.

When using asynchrous calls - using watcher.Start I get a access denied. When using watcher.waitfornextevent it works. Any idea why? I would really like to use the ansynchrous method.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ManagementPathString = "\\myserver\root\cimv2"
Query = "SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_Process'"

Dim oConn As ConnectionOptions = New ConnectionOptions()
oConn.Impersonation = ImpersonationLevel.Impersonate

oConn.Username = "myusername"
oConn.Password = "mypassword"

' Connect to the remote machine's WMI repository
Dim oMs As ManagementScope = New ManagementScope(ManagementPathString, oConn)
oMs.Options.Authentication = AuthenticationLevel.Default
oMs.Options.EnablePrivileges = True

Try
oMs.Connect()
Watcher = New ManagementEventWatcher(oMs, New EventQuery(Query))
MsgBox(oMs.IsConnected.ToString)
Catch ex As Exception
MsgBox("error: " & ex.ToString)
End Try
' connect it
Try
Console.WriteLine("Query: " & Query)
' start watching query
Watcher.Start()
Console.WriteLine("Watcher (eventlog) started")
While (Active)
' Do something while waiting for events
System.Threading.Thread.Sleep(intSleep)
End While
Catch ex As System.Management.ManagementException
err = ex.Message
Catch ex As Exception
err = ex.Message
End Try

MsgBox(err)
End Sub

Private Sub Watcher_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs) Handles Watcher.EventArrived
MsgBox(e.NewEvent.ToString)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top