Run a batch file on a remote computer as administrator

3

2

I am trying to run a batch file (to install some software) on a remote computer. To do this, I am using PSExec.

psexec.exe \\COMPUTER C:\swsetup\install.bat

This works fine, apart from some of the installs fail due to the script not running as an administrator (if I log on, right-click and select "Run as Administrator" the script runs and installs successfully.

I have tried running as administrator with the /runas command, with no luck

psexec.exe \\computer cmd

and then

runas /user:computer\administrator C:\swsetup\install.bat

The system flicks up with "Enter password for account" and then jumps back to the cmd prompt without letting me type the password in. The same issue happens if I try and do

runas /user:myaccount@domain.int C:\swsetup\install.bat

Is there a way around this, or am I going to have to visit the machine, log on, and then run the script on each machine?

tombull89

Posted 2014-07-11T11:29:01.133

Reputation: 6 533

Is the \install.bat located on the remote pc? – Ivan Viktorovic – 2014-07-11T14:14:43.840

@IvanViktorovic, yes. It was copied to the C:\swsetup folder on the remote machine. – tombull89 – 2014-07-11T14:19:32.037

2Try entering a remote PowerShell session instead? Enter-PSSession COMPUTER -Credential (Get-Credential) – Tanner Faulkner – 2014-07-11T14:33:36.040

Answers

1

Create a task schedule on remote computer that runs the batch file you want at highest privilege on demand. You might be able to add new task to remote computer with schtasks /Create /? (search add task schedule to remote computer)
create a shortcut to run task
run shortcut with psexec.exe

I use this method to bypass UAC when running select programs as admin. I created a new task scheduler folder "bypass UAC" and inside it new task "installer".

General tab: check "run with highest privilege".
Action tab:start a program yourbatchfile
Conditions tab: uncheck power restrictions and check wake computer if you have wake timers enabled and want to wake the computer to run the task.
Settings tab:check "allow task to be run on command"

For the shortcut use pattern: C:\Windows\System32\schtasks.exe /RUN /TN "foldername\taskname"

so for example "bypass UAC\installer"

If my instructions are confusing, search "bypass UAC with task scheduler"

Siavash

Posted 2014-07-11T11:29:01.133

Reputation: 11

Is it possible to make it generic? like %1? – barlop – 2015-07-06T08:38:49.003

yes, i think so if you make a batch file and before schtasks.exe /RUN ... you do schtasks.exe /change /tr %1 /TN "foldername\taskname".

and remember you can run schtasks on remote computers by specifying /S system /U user /P password – Siavash – 2015-07-15T20:58:54.623

0

Have you tried adding the PSExec password switch with the account name you're running the batch with?

 -p         Specifies optional password for user name. If you omit this
            you will be prompted to enter a hidden password.

Mitch

Posted 2014-07-11T11:29:01.133

Reputation: 859