1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| TreeList1.ClearNodes()
Dim Values As Object()
Dim ParentPresent As Boolean
Dim ParentParentPresent As Boolean
Dim ParentParentParentPresent As Boolean
Dim ParentId As Integer
Dim ParentParentId As Integer
Dim ParentParentParentId As Integer
Dim Node As TreeListNode
Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_Process")
For Each queryObj As ManagementObject In searcher.Get()
ParentPresent = False
ParentParentPresent = False
ParentParentParentPresent = False
If queryObj("ParentProcessId") = queryObj("ProcessId") Then
Dim classInstance As New ManagementObject("root\CIMV2", "Win32_Process.Handle='" & queryObj("Handle") & "'", Nothing)
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("GetOwner", Nothing, Nothing)
Values = New Object() {queryObj("Name"), outParams("User"), queryObj("ExecutablePath"), ConvertirDate(queryObj("CreationDate")), queryObj("ProcessId")}
Node = TreeList1.AppendNode(Values, -1)
TreeList1.ExpandAll()
End If
For i As Integer = 0 To TreeList1.Nodes.Count - 1
If TreeList1.Nodes(i).GetDisplayText(4) = queryObj("ParentProcessId") Then
If TreeList1.Nodes(i).GetDisplayText(4) <> queryObj("ProcessId") Then
ParentPresent = True
ParentId = TreeList1.Nodes(i).Id
End If
End If
For j As Integer = 0 To TreeList1.Nodes(i).Nodes.Count - 1
If TreeList1.Nodes(i).Nodes(j).GetDisplayText(4) = queryObj("ParentProcessId") Then
If TreeList1.Nodes(i).Nodes(j).GetDisplayText(4) <> queryObj("ProcessId") Then
ParentParentPresent = True
ParentParentId = TreeList1.Nodes(i).Nodes(j).Id
End If
End If
For k As Integer = 0 To TreeList1.Nodes(i).Nodes(j).Nodes.Count - 1
If TreeList1.Nodes(i).Nodes(j).Nodes(k).GetDisplayText(4) = queryObj("ParentProcessId") Then
If TreeList1.Nodes(i).Nodes(j).Nodes(k).GetDisplayText(4) <> queryObj("ProcessId") Then
ParentParentParentPresent = True
ParentParentParentId = TreeList1.Nodes(i).Nodes(j).Nodes(k).Id
End If
End If
Next
Next
Next
If ParentParentParentPresent = True Then
Dim classInstance As New ManagementObject("root\CIMV2", "Win32_Process.Handle='" & queryObj("Handle") & "'", Nothing)
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("GetOwner", Nothing, Nothing)
Values = New Object() {queryObj("Name"), outParams("User"), queryObj("ExecutablePath"), ConvertirDate(queryObj("CreationDate")), queryObj("ProcessId")}
Node = TreeList1.AppendNode(Values, ParentParentParentId)
TreeList1.ExpandAll()
End If
If ParentParentPresent = True Then
Dim classInstance As New ManagementObject("root\CIMV2", "Win32_Process.Handle='" & queryObj("Handle") & "'", Nothing)
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("GetOwner", Nothing, Nothing)
Values = New Object() {queryObj("Name"), outParams("User"), queryObj("ExecutablePath"), ConvertirDate(queryObj("CreationDate")), queryObj("ProcessId")}
Node = TreeList1.AppendNode(Values, ParentParentId)
TreeList1.ExpandAll()
End If
If ParentPresent = True Then
Dim classInstance As New ManagementObject("root\CIMV2", "Win32_Process.Handle='" & queryObj("Handle") & "'", Nothing)
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("GetOwner", Nothing, Nothing)
Values = New Object() {queryObj("Name"), outParams("User"), queryObj("ExecutablePath"), ConvertirDate(queryObj("CreationDate")), queryObj("ProcessId")}
Node = TreeList1.AppendNode(Values, ParentId)
TreeList1.ExpandAll()
End If
If ParentPresent = False Then
If ParentParentPresent = False Then
If ParentParentParentPresent = False Then
If Not queryObj("ProcessId") = 0 Then
Dim classInstance As New ManagementObject("root\CIMV2", "Win32_Process.Handle='" & queryObj("Handle") & "'", Nothing)
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("GetOwner", Nothing, Nothing)
Values = New Object() {queryObj("Name"), outParams("User"), queryObj("ExecutablePath"), ConvertirDate(queryObj("CreationDate")), queryObj("ProcessId")}
Node = TreeList1.AppendNode(Values, -1)
TreeList1.ExpandAll()
End If
End If
End If
End If
Next |