繁体   English   中英

Powershell 启动过程:组合凭据/WorkingDirectory 失败

[英]Powershell start-process : combinaison Credential/WorkingDirectory fail

我正在使用 powershell 作为另一个用户启动进程。 为此,我使用如下所示的“Start-Process”。

$creds = Get-Credential -UserName $Name -Message "Please enter authorized credentials"

Start-Process `
    -Credential $creds `
    "C:\MyPowerfullProcess.exe" `
    -RedirectStandardOutput $logOutputPath `
    -RedirectStandardError $logErrorPath `
    -WorkingDirectory $workingPath `
    -ArgumentList $processArg
Stop-Transcript

问题是 $workingPath 只能由用户 $creds 访问,而不能由启动 .ps1 脚本的用户访问。 Start-Process 命令通过此错误:“WorkingDirectory”无效 [..] DirectoryNotFoundException

启动进程

  • CategoryInfo: InvalidOperation: (:) [启动进程], DirectoryNotFoundException
  • FullyQualifiedErrorId:DirectoryNotFoundException,Microsoft.PowerShell.Commands.StartProcessCommand

尝试使用以下-Verb添加来指定运行方式。

$creds = Get-Credential -UserName $Name -Message "Please enter authorized credentials"

Start-Process `
    -Credential $creds `
    "C:\MyPowerfullProcess.exe" `
    -RedirectStandardOutput $logOutputPath `
    -RedirectStandardError $logErrorPath `
    -WorkingDirectory $workingPath `
    -ArgumentList $processArg `
    -Verb RunAsUser
Stop-Transcript

来源: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM