RunAs netonly 并保存凭据

Ste*_*nio 10 windows active-directory

我可以用runas /netonlyand开始一个进程,runas /savecred但我不能同时使用这两个标志。

有没有办法以不同的用户远程运行进程而不必每次都输入密码?

Nic*_*lay 6

另一个答案中,Jason 正确地指出runas /netonly不支持保存凭据,并且 Microsoft故意使其难以使用runas编码密码(来自批处理脚本)。

当您希望始终使用指定的凭据连接到给定服务(即)时,Stefano 在评论中指出的使用 Windows 凭据管理器的建议非常有用。myserver.mycompany.com:XXX

对于命令行解决方案,其行为类似于 runas.exe,但无需输入密码,我发现RunAs powershell 模块(似乎实现了此建议)非常有用:

  1. 通过在提升的 PowerShell 提示符中运行以下命令从 PowerShell 库进行安装(需要 Powershell v5 或 Windows 10):

    Install-Module RunAs
    
    Run Code Online (Sandbox Code Playgroud)
  2. 通过运行以下命令加密密码:

    # change `domain\username` as needed:
    ConvertFrom-SecureString (Get-Credential 'domain\username').Password
    
    Run Code Online (Sandbox Code Playgroud)

    这将提示您输入登录名和密码,并打印一个长的十六进制数字,您必须复制该数字。

  3. 现在您可以执行与使用相同的操作runas /netonly

    Import-Module RunAs
    
    # replace xxxx below with the encrypted password from step 2 (and `domain\username` too)
    # you might want to put this into your profile: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7
    $mycreds = New-Object Management.Automation.PSCredential('domain\username', (ConvertTo-SecureString 'xxxx'))
    
    runas -netonly $mycreds "c:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE"
    
    Run Code Online (Sandbox Code Playgroud)

PS 网上的许多资源建议使用psexec以不同用户身份运行。在了解了它的工作原理之后,我不认为它是一个可行的替代方案runas /netonly


Jas*_*ner 5

恐怕这是一个不受支持的选项,您可以提供 /netonly 或 /savecred 但不能同时提供:

runas [{/简介 | /noprofile}] [/env] [{/netonly | /savecred}] [/smartcard] [/showtrustlevels] [/trustlevel] /user: " "

更多信息:https : //technet.microsoft.com/en-us/library/cc771525.aspx