Results 1 to 2 of 2

Thread: Determine Explorer Shell ProcessID

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    65

    Determine Explorer Shell ProcessID

    Hi,

    Can anyone assist me with finding the ProcessID for "explorer.exe". ? (I am wanting to know the PID for this single executable and nothing else.)

    Any sample code would be useful.

    Thanks,
    Al.

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    47
    I used the following API's to get me the data of all processes on the computer. Here's what i used

    VB Code:
    1. 'consts
    2. Private Const TH32CS_SNAPPROCESS = &H2
    3.  
    4. ' Types
    5. Private Type PROCESSENTRY32
    6.          dwSize As Long
    7.          cntUsage As Long
    8.          th32ProcessID As Long           ' This process
    9.          th32DefaultHeapID As Long
    10.          th32ModuleID As Long            ' Associated exe
    11.          cntThreads As Long
    12.          th32ParentProcessID As Long     ' This process's parent process
    13.          pcPriClassBase As Long          ' Base priority of process threads
    14.          dwFlags As Long
    15.          szExeFile As String * 260  ' MAX_PATH
    16. End Type
    17.  
    18. ' Functions used
    19. Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _
    20.          ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
    21. Private Declare Function Process32First Lib "kernel32" ( _
    22.          ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
    23. Private Declare Function Process32Next Lib "kernel32" ( _
    24.          ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
    25.  
    26. 'Start of function or sub
    27.           Dim hWND As Long
    28.           Dim ProData As PROCESSENTRY32
    29.           Dim Ret As Long
    30.           Ret = 1
    31.           ProData.dwSize = Len(ProData) ' sets the ProData.dwSize to the size of the structure
    32.           hWND = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) ' Create snapshot of the first process
    33.           Ret = Process32First(hWND, ProData) ' Gets handle of first process
    34.           Do Until Ret = 0    ' get the rest of the processes
    35.               debug.print ProData.szExeFile
    36.               debug.print ProData.th32ProcessID
    37.           Ret = Process32Next(hWND, ProData) ' gets next Process handle
    38.           Loop
    39. 'end of sub or function

    hope this helps. This gets all process ID's and the names so you just have to filter for Explorer.exe
    Last edited by OctaneChicken; May 4th, 2004 at 11:41 AM.
    Dave

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