Programmatically using WMI to remotely run apps which access locally mapped drives relative to the remote machine.
-
The following code in theory should pop up a CMD window and show me the contents of a mapped drive mapped locally on a remote machine called "remote_workstation_a". I'm running this script from my workstation and when I do the CMD window pop's up and tells me access denied. I tried logging in on the local machine as the domain administrator then run this script again with no luck. I can't seem to figure out programmatically how to connect to a remote machine with a specific username and password yet still access the Win32_Process WMI object.
strComputer = "remote_workstation_a" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process") Error = objWMIService.Create("cmd.exe /K dir w:\", null, null, intProcessID) If Error = 0 Then Wscript.Echo "was started with a process ID of " _ & intProcessID & "." Else Wscript.Echo " could not be started due to error " & _ Error & "." End If
I know this is possible because there are tools that already exist (psexec and beyondexec naming two) that can do this. As an example with PSEXEC (from sysinternals.com):psexec \\remote_workstation_a -u MY_PDC_DOMAIN\Adminstrator -p PASSWORD -i cmd.exe /K dir w:\
This works so I know for certain this is possible I can't can't find anything clear in the WMI docs on MSDN to show me how to do this. Based on this I just need to encode the username and password of the account I would like to impersonate on the remote machine somehow (through the 'GetObject("winmgmts:" ...' call?). The obvious answer is to just use PSEXEC but I need to run this a whole lot of times (which would open up MANY MANY processes) and PSEXEC's source is not exactly available. Any hints or suggestions would be greatly appriciated. The whole point of me attempting this is to make the tech guy's life a bit easier when pushing updates to the compute farm. And while I'm at it why is all the WMI documentation so vague on almost everything? I'm eventually going to need to map a printer to each machine on the network and I'd love to do it though WMI but it's going to be a BIG BIG chore without some insight. Thanks, Sean -
The following code in theory should pop up a CMD window and show me the contents of a mapped drive mapped locally on a remote machine called "remote_workstation_a". I'm running this script from my workstation and when I do the CMD window pop's up and tells me access denied. I tried logging in on the local machine as the domain administrator then run this script again with no luck. I can't seem to figure out programmatically how to connect to a remote machine with a specific username and password yet still access the Win32_Process WMI object.
strComputer = "remote_workstation_a" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process") Error = objWMIService.Create("cmd.exe /K dir w:\", null, null, intProcessID) If Error = 0 Then Wscript.Echo "was started with a process ID of " _ & intProcessID & "." Else Wscript.Echo " could not be started due to error " & _ Error & "." End If
I know this is possible because there are tools that already exist (psexec and beyondexec naming two) that can do this. As an example with PSEXEC (from sysinternals.com):psexec \\remote_workstation_a -u MY_PDC_DOMAIN\Adminstrator -p PASSWORD -i cmd.exe /K dir w:\
This works so I know for certain this is possible I can't can't find anything clear in the WMI docs on MSDN to show me how to do this. Based on this I just need to encode the username and password of the account I would like to impersonate on the remote machine somehow (through the 'GetObject("winmgmts:" ...' call?). The obvious answer is to just use PSEXEC but I need to run this a whole lot of times (which would open up MANY MANY processes) and PSEXEC's source is not exactly available. Any hints or suggestions would be greatly appriciated. The whole point of me attempting this is to make the tech guy's life a bit easier when pushing updates to the compute farm. And while I'm at it why is all the WMI documentation so vague on almost everything? I'm eventually going to need to map a printer to each machine on the network and I'd love to do it though WMI but it's going to be a BIG BIG chore without some insight. Thanks, Sean