香港新浪網 MySinaBlog
« 上一篇 | 下一篇 »
Emily | 4th Dec 2006, 00:21 AM | Script | (954 Reads)

WMI Example: Win32_Process  (2)

 All Windows Platforms

 

' Number of Excel instances 

Sub TotalExcelProcessesRunning()
Dim strComputer As String
Dim objWMIService As Object
Dim colProcessList As Object
Dim objProcess As Object
Dim x As Double
Const XL As String = "EXCEL.EXE"

strComputer = "."

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

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

Set colProcessList = objWMIService.ExecQuery _
                         ("Select * from Win32_Process Where Name = '" & XL & "'")
     MsgBox XL & " instances = " & colProcessList.Count

Set objWMIService = Nothing
Set colProcessList = Nothing

End Sub