如何从命令提示符下以“以pipe理员身份运行”运行应用程序?

我有一个名为test.bat的batch file。 我在test.bat文件中调用下面的指令:

 start /min powershell.exe %sysdrive%\testScripts\testscript1.ps1 

当我通过命令提示符运行时,我的testscript运行成功。 我想以pipe理员身份运行它(就像我创build了桌面快捷方式并以pipe理员身份运行一样,不应提示input任何用户名或密码)。

我曾尝试在上面的test.bat添加/elevate/NOUAC参数,但没有运气。 我该如何解决这个问题?

我知道如何手动,但我希望这是从命令提示符执行。

(通过Marnix Klooster ):…没有使用任何额外的工具,如超级用户问题的答案中所build议的那样如何使用提升的权限从命令行运行程序

尝试这个:

 runas.exe /savecred /user:administrator "%sysdrive%\testScripts\testscript1.ps1" 

它第一次保存密码,不再重复。 也许当你改变pipe理员密码时,你会再次提示。

请参阅此TechNet文章: Runas命令文档

从命令提示符处:

 C:\> runas /user:<localmachinename>\administrator cmd 

或者,如果你连接到一个域名:

 C:\> runas /user:<DomainName>\<AdministratorAccountName> cmd 

它看起来像psexec -h是这样做的方式:

  -h If the target system is Windows Vista or higher, has the process run with the account's elevated token, if available. 

其中…似乎并没有在Sysinternals – PsExec在线文档中列出。

但它在我的机器上运行。