如何以“以管理员身份运行"运行应用程序从命令提示符?
我有一个名为 test.bat
的批处理文件.我在 test.bat
文件中调用以下指令:
I have a batch file called test.bat
. I am calling the below instructions in the test.bat
file:
start /min powershell.exe %sysdrive% estScripts estscript1.ps1
当我通过命令提示符运行它时,我的测试脚本运行成功.我想以管理员身份运行它(就像我创建了一个桌面快捷方式并以管理员身份运行.它不应该提示输入任何用户名或密码).
When I run this through the command prompt, my testscript is running successfully. I want to run it as administrator (as if I have created a desktop shortcut and run as administrator. It shouldn't prompt for any username or password).
我尝试在上面的 test.bat
中添加 /elevate
和 /NOUAC
参数,但没有成功.我该如何解决这个问题?
I have tried adding /elevate
and /NOUAC
parameters in the above test.bat
, but no luck. How do I fix this issue?
我知道如何手动执行此操作,但我希望从命令提示符执行此操作.
I know how to do it manually, but I want this to be executed from the command prompt.
(来自 Marnix Klooster):...无需使用任何其他工具,例如 超级用户问题的答案如何以提升的权限从命令行运行程序.)
(By Marnix Klooster): ...without using any additional tools, like those suggested in an answer to Super User question How to run program from command line with elevated rights.)
试试这个:
runas.exe /savecred /user:administrator "%sysdrive% estScripts estscript1.ps1"
第一次保存密码,不再询问.可能你修改管理员密码的时候会再次提示.
It saves the password the first time and never asks again. Maybe when you change the administrator password you will be prompted again.