Bonjour, j'ai un petit (et oui encore un lol) soucis, concernant l'utilisation du WMI en vb.net. Je m'en sers pour changer l'adresse ip d'un ordinateur distant (mais toujours sur le même réseau local). Voici ma fonction qui me permet de le faire :
Shared Function change_ton_ip(ByVal user As String, ByVal password As String, ByVal domain As String, _
ByVal addresse As String, ByVal new_ip As String, ByVal new_mask As String, ByVal new_gateway As String) As Integer
Try
Dim connection As New ConnectionOptions
connection.Username = user
connection.Password = password
connection.Authority = "ntlmdomain:" & domain
'Dim name As String
Dim scope As New ManagementScope("\" & addresse & "\root\CIMV2", connection)
scope.Connect()
Dim classInstance2 As New ManagementObject(scope, New ManagementPath("Win32_NetworkAdapterConfiguration.Index='1'"), Nothing)
' Obtain [in] parameters for the method
Dim inParams2 As ManagementBaseObject = classInstance2.GetMethodParameters("SetGateways")
' Add the input parameters.
inParams2("DefaultIPGateway") = New String() {new_gateway}
' Execute the method and obtain the return values.
Dim outParams2 As ManagementBaseObject = classInstance2.InvokeMethod("SetGateways", inParams2, Nothing)
'---------------------------------------------------
Dim classInstance As New ManagementObject(scope, New ManagementPath("Win32_NetworkAdapterConfiguration.Index='1'"), Nothing)
Dim inParams As ManagementBaseObject = classInstance.GetMethodParameters("EnableStatic")
' Add the input parameters.
inParams("SubnetMask") = New String() {new_mask}
inParams("IPAddress") = New String() {new_ip}
' Execute the method and obtain the return values.
Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("EnableStatic", inParams, Nothing)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
------------------- fin de la fonction
Elle marche c'est pas là le soucis, une fois l'ip changée (et le masque), bah mon appli se fige et je peux plus rien faire avec, je pense que c'est dut à mon "scope" qui est toujours connectée sur l'ip qui a été changée et qui n'est attribuée à personne. Alors j'ai regardé mais je peux pas faire de truc genre scope.disconnect :( Quelqu'un a une idée svp ?