2017-03-08 17 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 
相關問題