Reputation: 12212
I need to run an install script as an administrator. I tried several things but none of them works
runas /user:Administrator install.bat
The shell asks for the password, then opens a new shell windows, and closes it right away without executing the script
runas /user:Administrator "call install.bat"
The shell asks for the password, then failed with an error
Unable to run - call install.bat
2: The system cannot find the file specified
What I don’t understand is that if I run the command call install.bat
without the runas
part, the script is ran. It failed for the commands that need admin credentials but that’s expected.
I have 2 questions:
runas /user:Administrator "call install.bat"
Upvotes: 2
Views: 10145
Reputation: 21259
Use cmd.exe
which is your vehicle to interpret .cmd
and .bat
files.
runas /user:Administrator "cmd.exe /K install.bat"
or
runas /user:Administrator "cmd.exe /C install.bat"
check cmd.exe /?
for /K
and /C
.
Note: /C
is more likely what you want.
Side-note after your comment: runas
has a /env
option:
/env to use current environment instead of user's.
Upvotes: 2
Reputation: 573
Batch files are executed by the interpreter (cmd). In order to run script in privileged mode, you need cmd with raised priviledges. Try use cmd instead of call.
Upvotes: -1