Bonjour,
Je rencontre actuellement un petit soucis pour afficher les processus en cours d'exécutions sur une machine distante :
Je n'arrive pas à correctement gérer l'affichage des données de ExecutablePath :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 Public Sub GetProcessList(ByVal ComputerName As String) Dim maListProcess As New ListViewItem ' Query system for Operating System information Dim query As ObjectQuery Dim searcher As ManagementObjectSearcher Dim queryCollection As ManagementObjectCollection Dim m As ManagementObject frmProcessList.Show() query = New ObjectQuery("SELECT * FROM Win32_Process") searcher = New ManagementObjectSearcher(ConnectScope(ComputerName), query) 'queryCollection = searcher.Get() For Each m In searcher.Get() Console.WriteLine(m.ToString()) Console.WriteLine(m("ProcessId").ToString) Console.WriteLine(m("Name").ToString) Console.WriteLine(m("execpath").ToString) Console.WriteLine(m("handle").ToString) Next End Sub
Il me retourne l'exception NullReferenceException n'a pas été gérée.
Pour gérer cette exception j'ai ajouter ceci dans le for each :
Suite à quoi j'obtiens une nouvelle exception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 For Each m In searcher.Get() Dim execPath As String = "" If m("ExecutablePath") IsNot Nothing Then execPath = m("ExecutablePath").ToString End If Console.WriteLine(m.ToString()) Console.WriteLine(m("ProcessId").ToString) Console.WriteLine(m("Name").ToString) Console.WriteLine(m(execPath)) Console.WriteLine(m("handle").ToString) Next
L'exception ManagementException n'a pas été gérée.
J'ai donc fait un try catch pour récupérer l'exception :
après quoi le try catch me renvoie un :"non trouvé"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Try For Each m In searcher.Get() Dim execPath As String = "" If m("ExecutablePath") IsNot Nothing Then execPath = m("ExecutablePath").ToString End If Console.WriteLine(m.ToString()) Console.WriteLine(m("ProcessId").ToString) Console.WriteLine(m("Name").ToString) Console.WriteLine(m(execPath)) Console.WriteLine(m("handle").ToString) Next Catch e As Exception MsgBox(e.Message) End Try
et dans la console de sortie j'obtiens :
Il semble que c le seule élément qui me bloque car en affichant les autres éléments il ne semble pas y avoir de problème\\Machine_distante\root\cimv2:Win32_Process.Handle="0"
0
System Idle Process
Si quelqu'un a une idée pour géré ExecutablePath je suis preneur.
++
Je continue mes recherche
Partager