关于如何编写一个返回正在运行的进程实例数的函数的任何想法?
也许是这样的?
function numInstances([string]$process)
{
$i = 0
while(<we can get a new process with name $process>)
{
$i++
}
return $i
}
编辑:开始编写一个函数......它适用于单个实例,但如果有多个实例正在运行,它将进入无限循环:
function numInstances([string]$process)
{
$i = 0
$ids = @()
while(((get-process $process) | where {$ids -notcontains $_.ID}) -ne $null)
{
$ids += (get-process $process).ID
$i++
}
return $i
}