[英]Hello, I need to know how to start 10 notepad and then stop all 10 processes using cmdlets (powershell only)
Start-process notepad | 开始过程记事本| stop-process 停止过程
pretty much all I know what to do. 我几乎知道该怎么做。
Start-Process just starts a process; Start-Process只是启动一个过程; it does not provide a way to reference that process after it has been started. 它没有提供启动该过程后引用该过程的方法。 Another way to do it would be: 另一种方法是:
# // Declare an array to hold Process IDs
$aProcessIDs = @()
# // Create a Wscript.Shell object to use for running processes
$oWshShell = New-Object -ComObject Wscript.Shell
# // Start 10 instances of notepad
for ($i=1;$i -le 10;$i++)
{
# // Run notepad.exe
$oProcess = $oWshShell.Exec('notepad.exe')
# // Add the ProcessID of the running process to the array
$aProcessIDs += $oProcess.ProcessID
}
# /// Wait 10 seconds
Start-Sleep -s 10
# // Terminate all processes
foreach ($iProcessID in $aProcessIDs)
{
Stop-Process -Id $iProcessID
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.