使用 runas 命令运行脚本 [英] Running a script using the runas command
问题描述
我需要以管理员身份运行安装脚本.我尝试了几件事,但都没有奏效
I need to run an install script as an administrator. I tried several things but none of them works
runas /user:Administrator install.bat
shell 要求输入密码,然后打开一个新的 shell 窗口,并在不执行脚本的情况下立即关闭它
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"
shell 要求输入密码,然后失败并出现错误
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
我不明白的是,如果我在没有 runas
部分的情况下运行命令 call install.bat
,脚本会运行.需要管理员凭据的命令失败,但这是意料之中的.
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.
我有两个问题:
- 如何使用 runas 命令以管理员身份运行脚本?
- 您能否解释为什么以下调用不起作用:
runas/user:Administrator "call install.bat"
推荐答案
使用 cmd.exe
来解释 .cmd
和 .bat
文件.
Use cmd.exe
which is your vehicle to interpret .cmd
and .bat
files.
runas /user:Administrator "cmd.exe /K install.bat"
或
runas /user:Administrator "cmd.exe /C install.bat"
检查 cmd.exe/?
的 /K
和 /C
.
注意:/C
更可能是您想要的.
Note: /C
is more likely what you want.
评论后的旁注:runas
有一个 /env
选项:
Side-note after your comment: runas
has a /env
option:
/env to use current environment instead of user's.
这篇关于使用 runas 命令运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!