2017-04-10 29 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 
相关问题