如何在powershell中提示以不同的用户运行EXE?

问题描述 投票:2回答:2

我如何以不同的用户身份运行一个EXE? 我怎样才能提示凭证或者至少要求本地管理员输入密码,通过powershell启动一个exe。 我很难让runas命令工作。

这是我最新尝试的:runas -credential .\me c:\windows\system32\notepad.exe。

这在 powerhell terminal:runas user:asdf c:\windows\system32\notepad.exe 中可以工作,但在独立的 powershell 脚本中却没有要求提供证书。

powershell uac elevated-privileges runas
2个回答
2
投票

这是一个简单的操作。

Start-Process "c:\windows\system32\notepad.exe" -Credential $(Get-Credential)

使用Get-Credential会提示用户输入凭证,你也可以把它存储在一个变量中。

$Creds = Get-Credential
Start-Process "c:\windows\system32\notepad.exe" -Credential $Creds

-1
投票

请尝试以下操作

Start-Process notepad.exe -Verb RunAsUser
© www.soinside.com 2019 - 2024. All rights reserved.