4Eyes Posted April 21, 2011 Share Posted April 21, 2011 (edited) Folks, I wish to have a remote pc launch a program via WMI that resides on a network. I can launch a program on the remote pc via WMI, but only if that program is local, not on a network. Tried mapped drive letter, share etc. Example code below. expandcollapse popupGlobal $strComputer = "mikes-nb", $strUsername = "", $strPassword = "" ; From remote pc this works \\mikespc\sharename\DebugAgent.exe ; From remote pc this does not work \\192.168.1.102\sharename\DebugAgent.exe ; Fine... doesn't work with IP address spec'ing pc ;RemoteExecute("\\mikespc\c$\AutoITStuff\\agents\DebugAgent.exe") ; This doesn't work - using the full path ;RemoteExecute("\\share\DebugAgent.exe") ; This doesn't work - using a share ;RemoteExecute("p:\DebugAgent.exe") ; This doesn't work - using a drive letter mapped to a share ;RemoteExecute("cmd.exe /c start p:\DebugAgent.exe") ; This launches a process named cmd.exe but there is no window. ;RemoteExecute("cmd.exe /c p:\DebugAgent.exe") ; This launches a process named cmd.exe but there is no window. ;RemoteExecute("c:\windows\system32\calc.exe") ; This works - executes on local pc ;RemoteExecute("cmd.exe /c dir c:\windows\system32\calc.exe") ; This does nothing ;RemoteExecute("cmd.exe /c start c:\windows\system32\calc.exe") ; This launches a process named calc.exe but there is no window ; DebugAgent is simply a MsgBox. Thinking that maybe that's 'too interactive' I tried just Sleep(10000) to give long enought to see if anything happens, but no. ;***************************** ; This func runs the passed prog on the remote or local pc spec'ed by $strComputer. Will NOT show gui if remote, but will on local pc. Func RemoteExecute($strProgToRun) Local $objWMIService, $objProcess, $objProgram $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") If Not IsObj($objSWbemLocator) Then MsgBox(0, "Error", "Error: failed to create $objSWbemLocator") Exit EndIf $objWMI = $objSWbemLocator.ConnectServer($strComputer, "root\cimv2", $strUsername, $strPassword) ; This works for remote pc if pass actual credentials and works for local if pass null credentials If Not IsObj($objWMI) Then MsgBox(0, "Error", "Error: failed to create $objWMI") Exit EndIf $objWMI.Security_.ImpersonationLevel = 3 $objProcess = $objWMI.Get("Win32_Process") $objProgram = $objProcess.Methods_("Create").InParameters.SpawnInstance_ $objProgram.CommandLine = $strProgToRun $objWMI.ExecMethod("Win32_Process", "Create", $objProgram) ; Execute the program now at the command line. EndFunc ; End of Func RemoteExecute() ;***************************** I've found a number of different techniques in both VBS and AutoIT to launch a program on a remote pc but none work if that program is on a network. I truly do NOT understand. Maybe it's my setup, but I think not. Main pc is XP Pro SP3, remote is Win7 with UAC off. Admin on both. Could someone with 2 or more pc's please try this and advise? Alternatively, if there's a technique to launch an app on a remote pc not using WMI, but using AutoIT only then please advise. I do NOT want to use PSExec or have to install something on the remote pc. Thanks, 4Eyes Edited April 21, 2011 by 4Eyes Link to comment Share on other sites More sharing options...
kontdracula Posted October 31, 2012 Share Posted October 31, 2012 I have tested on remote machines , It is working without any problems... Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 31, 2012 Moderators Share Posted October 31, 2012 What is the error you are receiving when you run your script? Otherwise we're just guessing. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now