Results 1 to 2 of 2

Thread: Show All Processes In Vb..

  1. #1

    Thread Starter
    Junior Member VB Code's Avatar
    Join Date
    Dec 2004
    Location
    USA, California
    Posts
    30

    Show All Processes In Vb..

    Please give feed back.

    add a button with the name cmdRefresh
    add a button with the name cmdEnd
    add a list with the name of list1, make sure it has a scroll bar.




    FOLLOWING CODE IN A MODULE


    Option Explicit

    Public Const TH32CS_SNAPPROCESS As Long = 2&
    Public Const MAX_PATH As Long = 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 CreateToolhelp32Snapshot Lib "kernel32" _
    (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)

    Now, Put this code in form load.

    Private Sub Form_Load()

    cmdRefresh.Value = True
    Dim hSnapshot As Long
    Dim uProcess As PROCESSENTRY32
    Dim success As Long

    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)

    If hSnapshot = -1 Then Exit Sub

    uProcess.dwSize = Len(uProcess)
    success = ProcessFirst(hSnapshot, uProcess)

    If success = 1 Then

    Do
    List1.AddItem uProcess.szExeFile
    Loop While ProcessNext(hSnapshot, uProcess)

    End If

    Call CloseHandle(hSnapshot)

    End Sub

    PUT THIS IN REFRESH BUTTON

    Private Sub cmdRefresh_Click()
    List1.Clear

    Dim hSnapshot As Long
    Dim uProcess As PROCESSENTRY32
    Dim success As Long

    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)

    If hSnapshot = -1 Then Exit Sub

    uProcess.dwSize = Len(uProcess)
    success = ProcessFirst(hSnapshot, uProcess)

    If success = 1 Then

    Do
    List1.AddItem uProcess.szExeFile
    Loop While ProcessNext(hSnapshot, uProcess)

    End If

    Call CloseHandle(hSnapshot)

    End Sub

    PUT THIS IN END BUTTON

    Private Sub cmdEnd_Click()
    End
    End Sub
    I demand feedback, LOL

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Show All Processes In Vb..

    Ok, since you demand feedback, code for listing running processes are
    already in CodeBank at least three times.

    Note: CreateToolhelp32Snapshot is OS dependent. 2000+ or 95+.

    Its always best to do a search first.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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