0

启动进程记事本 | 停止进程

我几乎都知道该怎么做。

4

1 回答 1

1

Start-Process 只是启动一个进程;它不提供在启动后引用该进程的方法。另一种方法是:

# // 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
}
于 2016-06-30T06:02:43.973 回答