Link to home
Start Free TrialLog in
Avatar of Leif753
Leif753Flag for Sweden

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
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leif753

ASKER

hehe, much embarrassing. I used wrong account.

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