Results 1 to 2 of 2

Thread: retrieving all running programs

  1. #1

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134

    Post

    Is there anyone who knows how to retrieve a list of all programs running (and their HWND please) at the time the retrieve function/sub is called. I won't accept a DLL or OCX solution. Only plain API code, please.


  2. #2
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    All running programs with their HWNDS? I always thought, only windows have HWNDS..
    Anyways, I can give you an example to get all running processes with their process handles.
    Code:
    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)
    
    Public RProcesses() As PROCESSENTRY32
    Public Const PROCESS_TERMINATE = &H1
    Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    
    
    Public Sub GetRunningProcesses()
    
        Dim hSnapShot As Long
        Dim uProcess As PROCESSENTRY32
        Dim r As Long
        Dim i&
        ReDim RProcesses(0)
        hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
       
        If hSnapShot = 0 Then Exit Sub
    
        uProcess.dwSize = Len(uProcess)
        r = ProcessFirst(hSnapShot, uProcess)
        i = 1
        Do While r
            ReDim Preserve RProcesses(UBound(RProcesses) + 1)
            RProcesses(i) = uProcess
     
            i = i + 1
            r = ProcessNext(hSnapShot, uProcess)
    
        Loop
    
        Call CloseHandle(hSnapShot)
    
    End Sub
    All processes's handles and their path will be in RProcesses

    Hope I could help you
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

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