If Process Exists then

  • Thread starter Thread starter thomas
  • Start date Start date
You'll need to work through additional details but I would start by making
psapi.dll function EnumProcesses available by using a Declare statement.
The remaining steps depend on exactly what you are looking for,
 
I need the Excel VBA equivalent code for "If Process exists then....endif".


By "process" do you mean a Windows process? Or something else? I
think you
need to clarify exactly what you want to test for.
For a Windows process whose Process ID is known, use code similar to
the
following:

''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetProcessVersion Lib "kernel32" ( _
ByVal ProcessID As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long

Sub AAA()
Dim ProcID As Long
Dim Version As Long
Dim LastErr As Long
Dim ThisProcID As Long
ThisProcID = GetCurrentProcessId()
ProcID = 1234& ' specify process ID
' OR
ProcID = ThisProcID ' this process ID
Version = GetProcessVersion(ProcID)
LastErr = Err.LastDllError
If Version = 0 Then
If LastErr = &H57 Then
' processs does not exist
Debug.Print "Process does not exist"
Else
' process exists but access is denied
Debug.Print "Err: " & CStr(LastErr), _
GetSystemErrorMessageText(LastErr)
End If
Else
' process exists and is accessible:
Debug.Print "Process Exists. Version: " & Hex(Version)
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Windows process is what I mean and Chip, your code saves the day for me.

Thank you all, gentlemen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top