Jump to content

Unable to run a .bat file with psexec commands


Go to solution Solved by darweet,

Recommended Posts

Posted (edited)

Hi all, so I've been trying to write a script that'll run a local .bat file.

It's a simple idea that i run a batch file from autoit using the codes below with a simple run command.

#RequireAdmin

Run( 'C:\AutoTestPackage\TestSuite\SmokeTest\Configure\Temp_Basic.bat' ) 

Then the batch file will execute the  command line

psexec -i -d \\SGP101TEST02 -u TEST02 -p admin3t -f -c C:\AutoTestPackage\TestSuite\SmokeTest\Configure\Basic_Configuration.bat

 

 

However when i run the script below, the cmd window would appear but it gives an error saying

'psexec.exe' is not recognized as an internal or external command.

I also tried directly writing this in autoit

Run( @ComSpec & " /k C:\Windows\System32\PsExec.exe \\SGP101TEST02 C:\AutoTestPackage\TestSuite\SmokeTest\Configure\Temp_Basic.bat > C:\Temp\My.log")

 

But same error 
 
Can anyone tell me what was going on?
Btw if i run the .bat manually it worked!
Edited by darweet
Posted (edited)

Hi Darweet and welcome to the forums,

If i remember correctly, You need to specify a -c parameter for psexec to copy the batch file to the remote location (unless the bat file is already on the server/remote pc)

If the file is on your local pc, I would suggest using the following:

Run( @ComSpec & " /k C:\Windows\System32\PsExec.exe \\SGP101TEST02 -c -f C:\AutoTestPackage\TestSuite\SmokeTest\Configure\Temp_Basic.bat > C:\Temp\My.log")

The -c and -f parameters do the following:

-c : copy to remote location and execute

-f: force overwrite of file if already exists (tends to happen quite a bit if you're repeatedly testing your script)

EDIT: Seems i misread your first post by quite a landslide (apologies), Whilst your formatting for the psexec command could be better, It should be able to recognise the location, and you would see a psexec error if the formatting is incorrect.

I would suggest the following:

-Can you verify that psexec is in your system32 folder?

-Can you attempt to execute the script as an admin? - I've had issues previously accessing system32 for this very reason.

Hope this helps.

Javi

Edited by javiwhite

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

  • Solution
Posted

Thank you for the replies @javiwhite and @pcjunki !

At the end of the day I found out the problem. Turned out AutoIT was looking for PsExec.exe in 64-bit format.

In another post I found a solution:

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ;Prevent autoIT to look for 64-bit psexec.exe

After I added this line before where i call the batch file, everything works fine.

Anyway thanks for the replies guys!

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
  • Recently Browsing   0 members

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