Results 1 to 3 of 3

Thread: Process ID and Handles

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Process ID and Handles

    I have the processid to a program(the result returned when I shell something). I want to get its handle. How do I accomplish this?? Thank you very much for the help.

    Joe

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Code:
    Option Explicit
    
    Public Declare Function GetWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    
    Public Declare Function GetDesktopWindow Lib "user32" () As Long
    
    Public Declare Function GetWindowThreadProcessId Lib "user32" _
    (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    
    Public Declare Function BringWindowToTop Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
    _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
    As Any) As Long
    
    Public ProcessID As Long
    Public Const WM_CLOSE = &H10
    Public Const GW_HWNDFIRST = 0
    Public Const GW_HWNDNEXT = 2
    Public Const GW_CHILD = 5
    
    Public Function hWndFromProcessID(ProcID As Long) As Long
        Dim TempHandle As Long
        Dim GWTPIReturn As Long
        Dim CurrentProcID As Long
        On Error GoTo errHandler
        TempHandle = GetDesktopWindow()
        TempHandle = GetWindow(TempHandle, GW_CHILD)
        
        Do While TempHandle <> 0
            GWTPIReturn = GetWindowThreadProcessId(TempHandle,
    CurrentProcID)
            If CurrentProcID = ProcID Then
                hWndFromProcessID = TempHandle
                Exit Do
            End If
            TempHandle = GetWindow(TempHandle, GW_HWNDNEXT)
        Loop
        
        Exit Function
    errHandler:
        TempHandle = 0
    End Function
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Thanks...

    I actually found code just before you posted. It is the example for GetWindowThreadProcessId in the API-Guide from AllApi.net. Thank you very much for your help as well.

    JOe

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