获取同名进程的数量

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

Option Explicit
Dim objWMIService, objProcess, colProcess, strComputer, processName, instances

strComputer = "."
instances = 0
processName = "wscript.exe" 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

For Each objProcess in colProcess
If objProcess.Name = processName Then instances = instances + 1
Next

If processName = "wscript.exe" Then 
	If instances = 1 Then
	WScript.Echo "There is no other VBScript running except this one!"
	Else
	WScript.Echo "There are currently " & "(" & instances & ") " & "VBScript" & " Instances running!"
	End If
Else
	WScript.Echo "There are currently " & "(" & instances & ") " & """" & processName & """" & " Instances running!"
End If