如何以“以管理员身份运行"运行应用程序从命令提示符? [英] How to run an application as "run as administrator" from the command prompt?

查看:35
本文介绍了如何以“以管理员身份运行"运行应用程序从命令提示符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 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.

这篇关于如何以“以管理员身份运行"运行应用程序从命令提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆