Results 1 to 4 of 4

Thread: [RESOLVED] Help in getting the process information

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Resolved [RESOLVED] Help in getting the process information

    Hi,
    Its me again...
    Can any body help me in getting the processes and servics that are runing on my computer. Pls help its urgent..

    Regards.

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Help in getting the process information

    this gets the list of windows...

    in module
    VB Code:
    1. Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal Lparam As Long) As Long
    2. Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    3. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    4. Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    5.  
    6. Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal Lparam As Long) As Boolean
    7. Dim Strcaption As String, NSize As Long
    8.  
    9. NSize& = GetWindowTextLength(hwnd&)
    10.  
    11. Strcaption$ = Space$(NSize& + 1)
    12.  
    13. If IsWindowVisible(hwnd&) = 1 Then
    14.     Call GetWindowText(hwnd&, Strcaption$, Len(Strcaption$))
    15.    
    16.     If Strcaption$ <> Chr$(0) Then
    17.         frmMain.lstWindows.AddItem left$(Strcaption$, Len(Strcaption$) - 1)
    18.     End If
    19.     End If
    20.  
    21. EnumWindowsProc = True
    22.  
    23. End Function

    in command button or anything..
    VB Code:
    1. lstWindows.Clear
    2. Call EnumWindows(AddressOf EnumWindowsProc, 0&)

    it wil add the window captions to the listbox named lstWindows
    Last edited by the182guy; Mar 3rd, 2006 at 09:59 PM.
    Chris

  3. #3
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Help in getting the process information

    if you want to get the list of process exe names, like you see in task manager, then do it like this...

    i have a command button and a listbox on the form, this is my command button code
    VB Code:
    1. 'Get the processes
    2. Dim SnapShot As Long
    3. Dim Process As PROCESSENTRY32
    4.  
    5. Process.dwSize = Len(Process) 'define the DWORD size
    6. SnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) 'Get a snapshot of the processes
    7. Process32First SnapShot, Process 'Get first process
    8.  
    9. List1.AddItem Process.szexeFile 'Add first process to list
    10.  
    11. While Process32Next(SnapShot, Process) 'while a next process exists, get it
    12.     List1.AddItem Process.szexeFile 'Add to list
    13. Wend

    put this in a bas module
    VB Code:
    1. 'Snapshot API
    2. Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
    3. 'First process API
    4. Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Boolean
    5. 'Next process API
    6. Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Boolean
    7.  
    8. 'flag for snapshot API, this flag tells it to only give us the processes, no threads
    9. Public Const TH32CS_SNAPPROCESS As Long = 2&
    10.  
    11. 'type which is used to store info about the process
    12. Public Type PROCESSENTRY32
    13.     dwSize As Long
    14.     cntUsage As Long
    15.     th32ProcessID As Long
    16.     th32DefaultHeapID As Long
    17.     th32ModuleID As Long
    18.     cntThreads As Long
    19.     th32ParentProcessID As Long
    20.     pcPriClassBase As Long
    21.     dwFlags As Long
    22.     szexeFile As String * 260
    23. End Type
    Chris

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Help in getting the process information

    thankx man .....
    It really helped me a lot...
    Thankx a lot again!

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