Link to home
Start Free TrialLog in
Avatar of koneill99
koneill99

asked on

How do I pass credentials to remote machine using WMI in VB.NET

I am using the fiollowing code to enumerate users on a remote machine.  I got the code from this site.

In order to run the query on the remote machine, I have to pass it my username and password or I'll get access denied.

Does anyone know the syntax for passing the username & password?

Here is the code:
Private Sub EnumerateLocalAccounts(ByRef machineName As String)

      Dim pathMachine As New Management.ManagementPath("\\" & machineName & "\root\cimv2")
      Dim scopeRemoteMachine As New Management.ManagementScope(pathMachine)
      Dim queryAccounts As New Management.ObjectQuery( "SELECT * FROM Win32_Account")

      Dim searcherAccounts As New Management.ManagementObjectSearcher(scopeRemoteMachine, queryAccounts)

      Dim objectAccount As Management.ManagementObject

      For Each objectAccount In searcherAccounts.Get

         Debug.WriteLine(objectAccount("Name"))

      Next

   End Sub

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America 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