简体   繁体   English

启动进程内的启动进程作为不同的用户

[英]Start-Process inside start-process as different user

I'm trying to pass arguments from an installshield setup file, what am I doing wrong?我正在尝试从 installshield 设置文件中传递 arguments,我做错了什么?

$STExecute = "C:\Files\setup.exe"
$STArgument = '/s /f2"c:\windows\setuplogs\inst.log"'

Start-Process Powershell.exe -Credential "Domain\userTempAdmin" `
-ArgumentList "-noprofile -command &{Start-Process $($STExecute) $($STArgument) -verb runas}"

I get the blow error, as you can see it removes the double quotes, that needs to be there, I cant even get it to pass the /s argument in the 2nd start-process:我得到了打击错误,你可以看到它删除了需要存在的双引号,我什至无法让它在第二个启动过程中传递 /s 参数:

Start-Process : A positional parameter cannot be found that accepts argument '/f2c:\windows\setuplogs\dmap110_inst.log'

This is happening because the inner instance is seeing /s and /f2"c:\windows\setuplogs\inst.log" as two separate positional parameters.发生这种情况是因为内部实例将/s/f2"c:\windows\setuplogs\inst.log"视为两个单独的位置参数。 You need to wrap the arguments for the inner Start-Process with quotes.您需要用引号将内部Start-Process的 arguments 包装起来。 I'd also suggest using splatting to make it easier to understand what is happening:我还建议使用喷溅来更容易理解正在发生的事情:

$STExecute = "C:\Files\setup.exe"
$STArgument = '/s /f2"c:\windows\setuplogs\inst.log"'
$SPArgs = @{
    FilePath = 'powershell.exe'
    ArgumentList = "-noprofile -command Start-Process '{0}' '{1}' -Verb runas" -f
        $STExecute, $STArgument
}
Start-Process @SPArgs

I have also used the format operator here, as it allows us to inject values without using subexpressions.我在这里也使用了格式运算符,因为它允许我们在不使用子表达式的情况下注入值。 As long as there are no single quotes in $STArgument , or you escape them properly (four quotes '''' per quote in this case), it should work for you.只要$STArgument中没有单引号,或者您正确地转义它们(在这种情况下,每个引号四个引号'''' ),它就应该适合您。

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

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