2017-03-08 22 views
0

我有一个很艰难的时期传递引号.bat文件时提升,二进制文件似乎工作你...重现步骤:如何通过PowerShell中开始处理传递报价参数升高批处理脚本

创建含

echo.%* && pause 

火起来的PowerShell小试批处理脚本%TEMP%\test.bat和尝试这些:

# both behave like expected, echoing hello and pausing 
saps -filepath cmd -argumentlist '/c echo.hello && pause' 
saps -filepath "$env:TEMP\test.bat" -argumentlist 'hello' 

# both behave like expected, echoing "hello" and pausing 
saps -filepath cmd -argumentlist '/c echo."hello" && pause' 
saps -filepath "$env:TEMP\test.bat" -argumentlist '"hello"' 

# both behave like expected, echoing an elevated hello and pausing 
saps -verb runas -filepath cmd -argumentlist '/c echo.hello && pause' 
saps -verb runas -filepath "$env:TEMP\test.bat" -argumentlist 'hello' 

# cmd still echoes correctly "hell"no and pauses 
saps -verb runas -filepath cmd -argumentlist '/c echo."hell"no && pause' 

# tl;dr 

# now this is where hell breaks loose 
saps -verb runas -filepath "$env:TEMP\test.bat" -argumentlist '"hell"no' 
# doesnt echo anything, window pops up and vanishes in an instant 
# doesnt pause 

回答

0

的“运行方式”,如果你invok动词不起作用直接在批处理文件中。您需要在实际的可执行文件(即cmd.exe)上调用它并将该批处理文件作为参数传递。

$params = '/c', "$env:TEMP\test.bat", '"hell"no' 
Start-Process -Verb Runas -FilePath $env:ComSpec -ArgumentList $params 
相关问题