二
Private Sub CheckName(ByVal strProcessName As String)
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim strCheck As String
Const strComputer = "" ' Remote computer name (prefix With \\, i.e. \\ComputerName), leave blank For the local machine
Const WMIFLAGFORWARDONLY = 32
Const WMIFLAGRETURNIMMEDIATELY = 16
'Initialize
strCheck = vbNullString
Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\cimv2")
'Get Records, use the percent sign (%) a
' s a wildcard
Set colItems = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE NAME LIKE '" & strProcessName & "'", , _
WMIFLAGRETURNIMMEDIATELY + WMIFLAGFORWARDONLY)
'In case more than one process exists, b
' uild name list
For Each objItem In colItems
strCheck = strCheck & objItem.Name & vbCrLf
Next
'Display results
MsgBox "These processes match the name provided:" & vbCrLf & strCheck, _
vbInformation + vbOKOnly, "Process Check"
'Clean-up objects
Set objWMIService = Nothing
Set colItems = Nothing
End Sub
这个问题可以用WMI解决
Function IsProcessRunning( strServer, strProcess )
Dim Process, strObject
IsProcessRunning = False
strObject= "winmgmts://" & strServer
For Each Process In GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
Exit Function
End If
Next
End Function
Dim strComputer, strProcess
Do
strProcess = inputbox( "Please enter the name of the process (for instance: explorer.exe)", "Input" )
Loop until strProcess <> ""
Do
strComputer = inputbox( "Please enter the computer name", "Input" )
Loop until strComputer <> ""
If( IsProcessRunning( strComputer, strProcess ) = True ) Then
WScript.Echo "Process " & strProcess & " is running On computer " & strComputer
Else
WScript.Echo "Process " & strProcess & " is Not running On computer " & strComputer
End If