2016-06-30 43 views

Antwort

1

Start-Prozess startet nur einen Prozess; Es bietet keine Möglichkeit, nach dem Start auf diesen Prozess zu verweisen. Eine andere Möglichkeit wäre:

# // 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 
}