如何运行应用程序作为“以管理员身份运行”从命令提示符? [英] How to run an application as "run as administrator" from the command prompt?
问题描述
我有一个批处理文件 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%\testScripts\testscript1.ps1
通过命令提示符,我的testscript运行成功。我想以管理员身份运行它(就像我创建了一个桌面快捷方式并以管理员身份运行,不应该提示输入任何用户名或密码)。
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 $ c中添加
/ elevate
和 / NOUAC
$ c>,但没有运气。如何解决此问题?
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%\testScripts\testscript1.ps1"
$ b b
它第一次保存密码,而不再次询问。也许当您更改管理员密码时,系统会再次提示您。
It saves the password the first time and never asks again. Maybe when you change the administrator password you will be prompted again.
这篇关于如何运行应用程序作为“以管理员身份运行”从命令提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!