Hello
You may be interested in this method using the WMI instead of the API.
'Written: November 30, 2010
'Author: Leith Ross
'Summary: Count the instances of a running executable program
Sub ShowProgramCount()
Dim Cnt As Long
Dim colProcesses As Variant
Dim Msg As String
Dim objSWbemServices As Object
Dim objProcess As Object
Dim ProgramX As String
Dim ThisComputer As String
ProgramX = InputBox("Enter the name of the exectable file below.")
If ProgramX = "" Then Exit Sub Else ProgramX = LCase(ProgramX)
ThisComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & ThisComputer)
Set colProcesses = objSWbemServices.InstancesOf("Win32_Process")
For Each objProcess In colProcesses
'Msg = Msg & Process.Name & vbCrLf
If LCase(objProcess.Name) Like ProgramX Then
Cnt = Cnt + 1
End If
Next objProcess
MsgBox "Number of '" & ProgramX & "' Programs Open: " & Cnt
Set objProcess = Nothing
Set objSWbemServices = Nothing
End Sub
Bookmarks