返回顶部

收藏

vb获取同名进程的数量

更多

获取同名进程的数量

[ASP/Basic]代码

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

标签:vb,进程

收藏

0人收藏

支持

0

反对

0

发表评论