CodeItBetter Programming Another VB Programming Blog

How to check which programs are currently running

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'System & API - How to check which programs are currently running

'Add a List Box and a Command Button to your form.

Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Integer = 260
Public Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
End Type
Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" _
    (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "Kernel32" Alias "Process32First" (ByVal hSnapShot As Long, _
    uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "Kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, _
    uProcess As PROCESSENTRY32) As Long
Public Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
 
Private Sub Command1_Click()
    Dim hSnapShot As Long, r As Long
    Dim uProcess As PROCESSENTRY32
    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    If hSnapShot = 0 Then Exit Sub
    uProcess.dwSize = Len(uProcess)
    r = ProcessFirst(hSnapShot, uProcess)
    Do While r
        List1.AddItem uProcess.szExeFile
        r = ProcessNext(hSnapShot, uProcess)
    Loop
    Call CloseHandle(hSnapShot)
End Sub

Related posts:

  1. How to find and terminate running applications
  2. How to Retrieve the FilePath from process identified using a hwnd
  3. How to Change the Priority of any Running Process
  4. How to check whether the program is running under Win32 (i.e. any 32-bit operating system)
  5. How to check whether the system is connected with internet (in two ways)
  6. How to check which Drive is CD Drive
  7. How to terminate an application
  8. How to check if a task exists by searching for (part or all of) the window title
  9. How to Start another program using Shell and wait until it finishes.
  10. How to check whether the file system is FAT 32 or NTFS

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.