Leif753
asked on
Access Denied Querying with WMI
Hi Experts out there!!
I am trying to access the network adapters using WMI. I am trying with the code below. I get access denied on the "scope.connect"-line. Any ideas? I am creating a Windows application
I am trying to access the network adapters using WMI. I am trying with the code below. I get access denied on the "scope.connect"-line. Any ideas? I am creating a Windows application
Dim mgmtOptions As New ConnectionOptions
mgmtOptions.Impersonation = ImpersonationLevel.Impersonate
mgmtOptions.Authentication = AuthenticationLevel.Connect
Dim scope = New ManagementScope("\\" + RemotePC + "\root\cimV2", mgmtOptions)
scope.connect()
Dim QueryNIC As ObjectQuery
QueryNIC = New ObjectQuery("SELECT * FROM Win32_NetworkAdapter")
Dim NICSearcher As New ManagementObjectSearcher(scope, QueryNIC)
Dim Queried As ManagementObject
For Each Queried In NICSearcher.Get()
Debug.Print(Queried!ProductName)
Debug.Print(Queried!Name)
Debug.Print(Queried!Index)
Debug.Print(Queried!NetConnectionID)
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
However I got another problem. I the error:"The application called an interface that was marshalled for a different thread." on this line: For Each Queried In NICSearcher.Get()
And I am not using several threads