Results 1 to 6 of 6

Thread: Find all Processes:

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Find all Processes:

    In a module:
    VB Code:
    1. Option Explicit
    2. Public strstr As String
    3. Const MAX_PATH& = 260
    4.  
    5. Declare Function ProcessFirst _
    6. Lib "kernel32" Alias "Process32First" _
    7. (ByVal hSnapshot As Long, _
    8. uProcess As PROCESSENTRY32) As Long
    9. Declare Function ProcessNext _
    10. Lib "kernel32" Alias "Process32Next" _
    11. (ByVal hSnapshot As Long, _
    12. uProcess As PROCESSENTRY32) As Long
    13. Declare Function CreateToolhelpSnapshot _
    14. Lib "kernel32" Alias "CreateToolhelp32Snapshot" _
    15. (ByVal lFlags As Long, _
    16. lProcessID As Long) As Long
    17. Declare Function CloseHandle _
    18. Lib "kernel32" (ByVal hObject As Long) As Long
    19.  
    20.  
    21. Type PROCESSENTRY32
    22. dwSize As Long
    23. cntUsage As Long
    24. th32ProcessID As Long
    25. th32DefaultHeapID As Long
    26. th32ModuleID As Long
    27. cntThreads As Long
    28. th32ParentProcessID As Long
    29. pcPriClassBase As Long
    30. dwFlags As Long
    31. szexeFile As String * MAX_PATH
    32. End Type
    Form:
    VB Code:
    1. Private Sub Form_Load()
    2. Call Getlist
    3. End Sub
    4.  
    5. Private Function Getlist()
    6. Const TH32CS_SNAPPROCESS As Long = 2&
    7. Dim uProcess As PROCESSENTRY32
    8. Dim rProcessFound As Long
    9. Dim hSnapshot As Long
    10. Dim szExename As String
    11. Dim appCount As Integer
    12. Dim I As Integer
    13.  
    14. uProcess.dwSize = Len(uProcess)
    15. hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    16. rProcessFound = ProcessFirst(hSnapshot, uProcess)
    17. Do While rProcessFound
    18. I = InStr(1, uProcess.szexeFile, Chr(0))
    19. szExename = LCase$(Left$(uProcess.szexeFile, I - 1))
    20. rProcessFound = ProcessNext(hSnapshot, uProcess)
    21. List1.AddItem szExename'''szexename is each process name
    22. Loop
    23. End Function
    enjoy it people

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Find all Processes:

    Very nice, but I do have a question (which is probably picky).

    Since you are not looking for a return value, I was wondering why GetList is a Function rather than a Sub?

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Find all Processes:

    Nice code |2eM!x

    Quote Originally Posted by Hack
    Very nice, but I do have a question (which is probably picky).

    Since you are not looking for a return value, I was wondering why GetList is a Function rather than a Sub?
    Does that really matter anyway?


    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Find all Processes:

    Quote Originally Posted by sciguyryan
    Nice code |2eM!x



    Does that really matter anyway?


    Cheers,

    RyanJ
    In terms of functionality no...but it is contrary to my sense of consistency (Ok, ok...I know...I'm picky...what can I say? )

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Find all Processes:

    guess nothing...but it looks cool : D

  6. #6
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Find all Processes:

    in your routine, is it possible to tell if a given process has a window? and if its a window, can i get its handle? without enumerating all the windows.

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