willichan Posted March 13, 2015 Share Posted March 13, 2015 I am trying to push execution of an EXE on a set of machines on my network. I am probably missing something simple, but I cannot make the code below work. PushIt("testpc") Func PushIt($pcname) $executor = @ComSpec & " /c " & @ScriptDir & "\PsExec.exe \\" & $pcname & " -s -d C:\Windows\apptopush.exe" If Ping($pcname, 2000) = 0 Then Return 0 If Not FileCopy("apptopush.exe", "\\" & $pcname & "\c$\Windows\", 1) Then Return 0 RunWait($executor, @SW_SHOW) ConsoleWrite($executor & @CRLF) Return 1 EndFunc ;==>PushIt I have full admin rights on all of the local PCs, including the 'testpc', so this is running with my domain credentials. When I run it, the exe copies to the remote system, but the exe never executes on the remote system. If I copy the command from the console, and paste it into a CMD shell from the script path, it runs the exe on the remote, no problem. What am I missing? My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
jdelaney Posted March 13, 2015 Share Posted March 13, 2015 (edited) Output $executor = @ComSpec & " /c " & @ScriptDir & "PsExec.exe " & $pcname & " -s -d C:Windowsapptopush.exe" to the console, and run it directly through a cmd prompt...see what the actual failure is. switch the /c to a /k...or just psexec directly. Edited March 13, 2015 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
willichan Posted March 13, 2015 Author Share Posted March 13, 2015 (edited) jdelaney, Switching to /k, or leaving comspec off entirely does not seem to make any difference. It works from the command line, but not from within the script. There are no error messages. It says started on testpc with process ID xxxxx, and actually runs on the remote system when run from the cmd prompt. Edited March 13, 2015 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
jdelaney Posted March 13, 2015 Share Posted March 13, 2015 -c Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the remote system. You should play around with -c...it will copy over the exe without the filecopy() Also, add a #requireadmin at the top of your script. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
willichan Posted March 13, 2015 Author Share Posted March 13, 2015 (edited) -c Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the remote system. You should play around with -c...it will copy over the exe without the filecopy() Also, add a #requireadmin at the top of your script. Thank you for your suggestions. The -c parameter was causing other problems. That is why I went with filecopy(). Since I am dropping the file in the Windows folder, it is in the system path. I am also using #requireadmin, though I did not include it in the reproducer script. In this particular case, the problem is not with getting correct parameters for PsExe (since the same command works from the CMD prompt), but rather with getting it to run from within a script. Edited March 13, 2015 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Solution willichan Posted March 16, 2015 Author Solution Share Posted March 16, 2015 (edited) Well, I never figured out why PSEXEC was working in the command line, but not from a script. I did, however find a workaround. I output the command line to a .CMD file, then run that. PushIt("testpc") Func PushIt($pcname) $executor = @ComSpec & " /c " & @ScriptDir & "\PsExec.exe \\" & $pcname & " -s -d C:\Windows\apptopush.exe" If Ping($pcname, 2000) = 0 Then Return 0 If Not FileCopy("apptopush.exe", "\\" & $pcname & "\c$\Windows\", 1) Then Return 0 $outfile = FileOpen(@ScriptDir & "push.cmd", $FO_OVERWRITE) FileWriteLine($outfile, $executor) FileClose($outfile) RunWait($executor, @SW_SHOW) ConsoleWrite($executor & @CRLF) Return 1 EndFunc ;==>PushIt A bit kludgey, but it works. Edited March 16, 2015 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash 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