Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

powershell - 如何从命令提示符“以管理员身份运行”运行应用程序? [关闭](How to run an application as “run as administrator” from the command prompt? [closed])

I have a batch file called test.bat .

(我有一个名为test.bat的批处理文件。)

I am calling the below instructions in the test.bat file:

(我在test.bat文件中调用以下说明:)

start /min powershell.exe %sysdrive%estScriptsestscript1.ps1

When I run this through the command prompt, my testscript is running successfully.

(当我通过命令提示符运行时,我的testscript运行成功。)

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).

(我想以管理员身份运行它(就像我创建了一个桌面快捷方式并以管理员身份运行。它不应该提示任何用户名或密码)。)

I have tried adding /elevate and /NOUAC parameters in the above test.bat , but no luck.

(我已经尝试在上面的test.bat添加/elevate /NOUAC/NOUAC参数,但没有运气。)

How do I fix this issue?

(我该如何解决这个问题?)

I know how to do it manually, but I want this to be executed from the command prompt.

(我知道如何手动执行,但我希望从命令提示符执行此操作。)

(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 .)

((作者Marnix Klooster ):...不使用任何其他工具,例如在回答超级用户问题时建议的那些工具如何从具有提升权限的命令行运行程序 。))

  ask by Praveen Jakkaraju translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

(试试这个:)

runas.exe /savecred /user:administrator "%sysdrive%estScriptsestscript1.ps1" 

It saves the password the first time and never asks again.

(它第一次保存密码,永远不会再问。)

Maybe when you change the administrator password you will be prompted again.

(也许当您更改管理员密码时,系统会再次提示您。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...