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(ByR ef machineName As String)
Dim pathMachine As New Management.ManagementPath( "\\" & machineName & "\root\cimv2")
Dim scopeRemoteMachine As New Management.ManagementScope (pathMachi ne)
Dim queryAccounts As New Management.ObjectQuery( "SELECT * FROM Win32_Account")
Dim searcherAccounts As New Management.ManagementObjec tSearcher( scopeRemot eMachine, queryAccounts)
Dim objectAccount As Management.ManagementObjec t
For Each objectAccount In searcherAccounts.Get
Debug.WriteLine(objectAcco unt("Name" ))
Next
End Sub
Thanks.
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(ByR
Dim pathMachine As New Management.ManagementPath(
Dim scopeRemoteMachine As New Management.ManagementScope
Dim queryAccounts As New Management.ObjectQuery( "SELECT * FROM Win32_Account")
Dim searcherAccounts As New Management.ManagementObjec
Dim objectAccount As Management.ManagementObjec
For Each objectAccount In searcherAccounts.Get
Debug.WriteLine(objectAcco
Next
End Sub
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.