This is excellent!
I've been looking for a way to check whether a specific app is running or not, and act accordingly.
This code works fine - slightly adapted, using it as a Boolean Function

thanks..!

VB Code:
  1. Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
  2. Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  3. Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  4. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  5. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  6.  
  7. Private Const TH32CS_SNAPPROCESS As Long = 2&
  8. Private Const MAX_PATH As Integer = 260
  9.  
  10. Private Type PROCESSENTRY32
  11.     dwSize As Long
  12.     cntUsage As Long
  13.     th32ProcessID As Long
  14.     th32DefaultHeapID As Long
  15.     th32ModuleID As Long
  16.     cntThreads As Long
  17.     th32ParentProcessID As Long
  18.     pcPriClassBase As Long
  19.     dwFlags As Long
  20.     szExeFile As String * MAX_PATH
  21. End Type
  22.  
  23. Private Sub Form_Load()
  24. Dim lLng As Long, lA As Long, lExCode As Long
  25. Dim procObj As PROCESSENTRY32
  26. Dim hSnap As Long
  27. Dim lRet As Long
  28. Dim sExeNam As String
  29.  
  30. sExeNam$ = "YourProgramName.exe"
  31. hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&) 'create a snapshot of the system process information
  32. procObj.dwSize = Len(procObj)
  33. lRet = Process32First(hSnap, procObj) 'Query information on the top-most running process
  34.  
  35. Do While Process32Next(hSnap, procObj) 'loop through all the processes
  36.     If InStr(1, LCase(procObj.szExeFile), LCase(sExeNam$)) > 0 Then 'Your exe name has been found
  37.         lLng = OpenProcess(&H1, ByVal 0&, procObj.th32ProcessID) 'Open the process as to get its handle
  38.         lA = TerminateProcess(lLng, lExCode) 'Terminate the process
  39.         Exit Do
  40.     End If
  41. Loop
  42. End Sub
[/QUOTE]