2017-04-10 50 views

回答

0

創建一個名爲run.ps1與文件,內容如下:

$apps = New-Object System.Collections.Generic.List[Object] 

$app = Start-Process "notepad.exe" -passthru 
$apps.Add($app) 

$app = Start-Process "notepad.exe" -passthru 
$apps.Add($app) 

Write-Host "Press any key to terminate ..." 
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 

#Kill the running processes 
foreach ($app in $apps) 
{ 
    Write-Host "Killing" ($app.Id -as [string]) 
    Stop-Process $app.Id 
} 

現在你可以使用執行:

powershell.exe -executionpolicy remotesigned -File ./test.ps1 
相關問題