【问题标题】:How to prompt to run EXE as different user in powershell如何在powershell中提示以不同用户身份运行EXE
【发布时间】:2015-10-27 20:09:12
【问题描述】:

我将如何以不同的用户身份运行 EXE?我如何提示输入凭据或至少要求本地管理员通过 powershell 启动 exe 的密码。我很难让 runas 命令正常工作。

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

这适用于 powershell 终端: runas /user:asdf c:\windows\system32\notepad.exe 但在独立的 powershell 脚本中不要求提供凭据。

【问题讨论】:

  • “我很难让 runas 命令正常工作:请告诉 as a edit to the question 你试图让 runas 命令正常工作的原因
  • 请给@Nick 点赞并将其标记为已回答。
  • 它在 PowerShell 命令行 shell 中工作,因为 powershell 可以从命令行运行大多数可执行文件。 Start-ProcessInvoke-Command 用于运行命令(PS 或外部),就像从命令行运行一样。

标签: powershell uac elevated-privileges runas


【解决方案1】:

这是一个简单的操作。

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

使用 Get-Credential 将提示用户输入凭据,您也可以将其存储在变量中。

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

【讨论】:

    【解决方案2】:

    将目录更改为 .exe 目录并运行以下命令

    runas /netonly /user:<domain\username> .\<app name>
    

    【讨论】:

      【解决方案3】:

      尝试关注

      Start-Process notepad.exe -Verb RunAsUser
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-16
        • 2013-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多