[VB.NET] WMI passer les postes en DHCP - erreur rpc failed
Bonjour,
Je dois réaliser en entreprise une application qui force les machines au sein d'un réseau à basculer en DHCP. J'ai écrit le code suivant, mais je suis bloqué car lors de l'éxécution un message d'erreur s'affiche:
Echec de l'appel de procédure distante (HRESULT: 0x800706BE).
Malgré ce message le poste bascule bien en DHCP mais mon application se bloque. Je pense que comme le poste bascule en DHCP il ne répond plus et donc la connexion rpc est rompue.
Code:
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
|
Dim connexion As New ConnectionOptions
Dim managementscope As New ManagementScope("\\" & strComputer & "\root\cimv2", connexion)
Dim objquery As ObjectQuery = New ObjectQuery("select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
Dim oService As System.Management.ManagementObject
Dim Searcher As New System.Management.ManagementObjectSearcher(managementscope, objquery)
managementscope.Connect()
Dim objcollection As ManagementObjectCollection = Searcher.Get
For Each oService In objcollection
Try
Dim outParams As ManagementBaseObject = oService.GetMethodParameters("enableDHCP")
oService.InvokeMethod("enableDHCP", outParams, Nothing)
MessageBox.Show("DHCP activé")
Exit For
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException
MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
End Try
Next |
Si quelqu'un à déjà rencontré ce problème ou bien qui a une idée je suis preneur.
Merci.