Jump to content

PsExec.exe not working from AU3 script


Go to solution Solved by willichan,

Recommended Posts

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?

Link to comment
Share on other sites

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 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

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 by willichan
Link to comment
Share on other sites

     -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

-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 by willichan
Link to comment
Share on other sites

  • Solution

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 by willichan
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...