Get all process and thread in Visual Basic

Get all process and thread in Visual Basic


You could get all the process running on your computer in visual basic with a very simple command. Use the Process.GetProcesses method to get almost everything on process on your Windows.





Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim oAllProcess() As System.Diagnostics.Process
        Dim oProcess As System.Diagnostics.Process
        Dim str As String
        Try
            str = ""
            oAllProcess = Process.GetProcesses()
            For index1 = 0 To oAllProcess.Length - 6 Step 5
                oProcess = oAllProcess(index1)
                str = str & oAllProcess(index1).ProcessName & "     " & _
                    oAllProcess(index1 + 1).ProcessName & "     " & _
                    oAllProcess(index1 + 2).ProcessName & "     " & _
                    oAllProcess(index1 + 3).ProcessName & "     " & _
                    oAllProcess(index1 + 4).ProcessName & "     " & _
                    oAllProcess(index1 + 5).ProcessName & vbCrLf
            Next
        Catch ex As Exception
        Finally

            MsgBox(str)
        End Try
      

    End Sub



How could you get all the threads in a process?
Is very simple, use the same process method to get all the thread running under each process. Using the same loop, use the property .Threads

Here is a sample and this could give you al lot of information on threads and process on your computer:



    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim oAllProcess() As System.Diagnostics.Process
        Dim oProcess As System.Diagnostics.Process
        Dim str As String
        Try
            str = ""
            oAllProcess = Process.GetProcesses()
            For index1 = 0 To oAllProcess.Length - 6 Step 5
                oProcess = oAllProcess(index1)
                str = str & oAllProcess(index1).ProcessName & " " & oAllProcess(index1).Threads.Count & "     " & _
                    oAllProcess(index1 + 1).ProcessName & " " & oAllProcess(index1 + 1).Threads.Count & "     " & _
                    oAllProcess(index1 + 2).ProcessName & " " & oAllProcess(index1 + 2).Threads.Count & "     " & _
                    oAllProcess(index1 + 3).ProcessName & " " & oAllProcess(index1 + 3).Threads.Count & "     " & _
                    oAllProcess(index1 + 4).ProcessName & " " & oAllProcess(index1 + 4).Threads.Count & "     " & _
                    oAllProcess(index1 + 5).ProcessName & " " & oAllProcess(index1 + 5).Threads.Count & vbCrLf

                oProcess = oAllProcess(index1).Threads.Count
            Next
           
        Catch ex As Exception
        Finally

            MsgBox(str)
        End Try

    End Sub




Related Posts by Categories

0 komentar:

Posting Komentar