2017-01-13 415 views
0

如何從AutoIt代碼執行PowerShell腳本?從Autoit執行powershell腳本?

我認爲它可能是這樣的:

Runwait(@ComSpec & " /c powershell.exe c:\Mytest.ps1", "", @SW_HIDE) 

Runwait(powershell.exe c:\Mytest.ps1", "", @SW_HIDE) 

但無論是那些似乎工作。

+0

'powershell.exe -File C:\ MyTest.ps1'(如果腳本執行策略允許)。 –

回答

2
Runwait("powershell.exe c:\Mytest.ps1", "", @SW_HIDE) 

和AU3文件點擊右鍵並選擇 '運行腳本(x64)的',我用

測試PowerShell腳本:

"heelllo" >> h:\somesome.txt 
+0

謝謝,這基本上工作......當我右鍵單擊並作爲「運行腳本(x64)」運行它工作正常......但是當我在SciTE腳本編輯器中打開腳本,並運行腳本按「F5」......它從那裏不起作用。有什麼想法嗎?我嘗試在Windows中以管理員身份運行腳本編輯器,但沒有任何結果 – user952342

0

我結束,這種解決方案似乎工作:

Local $iPID = Run('powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file C:\MyScript.ps1"', "c:\", @SW_HIDE, $STDOUT_CHILD) 
; Wait until the process has closed using the PID returned by Run. 
ProcessWaitClose($iPID) 
; Read the Stdout stream of the PID returned by Run. 
Local $sOutput = StdoutRead($iPID)