Results 1 to 14 of 14

Thread: [RESOLVED] Identifying if another Application is currently in memory?

Threaded View

  1. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    This will list all running processes (that includes EXE's, DLL's etc). Add a List box (List1) and a command button to a form. Paste this code into a module
    VB Code:
    1. Public Const TH32CS_SNAPPROCESS As Long = 2&
    2. Public Const MAX_PATH As Integer = 260
    3.  
    4. Public Type PROCESSENTRY32
    5.     dwSize As Long
    6.     cntUsage As Long
    7.     th32ProcessID As Long
    8.     th32DefaultHeapID As Long
    9.     th32ModuleID As Long
    10.     cntThreads As Long
    11.     th32ParentProcessID As Long
    12.     pcPriClassBase As Long
    13.     dwFlags As Long
    14.     szExeFile As String * MAX_PATH
    15. End Type
    16.  
    17. Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    18. Public Declare Function ProcessFirst Lib "Kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    19. Public Declare Function ProcessNext Lib "Kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    20. Public Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
    Then place this in the click event of the command button on the form
    VB Code:
    1. Dim hSnapShot As Long
    2. Dim uProcess As PROCESSENTRY32
    3. Dim r As Long
    4.  
    5. hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    6.  
    7. If hSnapShot = 0 Then
    8.     Exit Sub
    9. End If
    10.  
    11. uProcess.dwSize = Len(uProcess)
    12. r = ProcessFirst(hSnapShot, uProcess)
    13.  
    14. Do While r
    15.     List1.AddItem uProcess.szExeFile
    16.     r = ProcessNext(hSnapShot, uProcess)
    17. Loop
    18.  
    19. Call CloseHandle(hSnapShot)
    You can then modify it to suit what you need...for example to see if IE is open, modify the Do Loop like so...
    VB Code:
    1. Do While r
    2.     If InStr(1, uProcess.szExeFile, "IEXPLORE.EXE", vbTextCompare) > 0 Then
    3.         MsgBox "Internet Explorer is running!", vbInformation
    4.     End If
    5.     r = ProcessNext(hSnapShot, uProcess)
    6. Loop
    Last edited by chrisjk; Jul 7th, 2001 at 07:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width