Bonjour,

Je cherche à pouvoir via code changer l'adresse ip d'une carte réseau. J'ai trouvé cette fonction à l'origine en c# que j'ai convertit en VB.NET, elle fonctionne a merveille (aucune exception) mais l'ip ne change pas : : Quelqu'un voit une faute ou une erreur ?

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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
Public Sub setIP(ByVal IPAddress() As String, ByVal SubnetMask() As
 String, ByVal Gateway() As String)
 
 
        Dim objMC As Management.ManagementClass = New
 Management.ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim objMOC As Management.ManagementObjectCollection =
 objMC.GetInstances()
 
 
        Dim objMO As Management.ManagementObject
        For Each objMO In objMOC
            If (CType(objMO("IPEnabled"), Boolean) And objMO
("Index").ToString() = "11") Then
                Try
                    Dim objNewIP As Management.ManagementBaseObject =
 Nothing
                    Dim objSetIP As Management.ManagementBaseObject =
 Nothing
                    Dim objNewGate As Management.ManagementBaseObject =
 Nothing
 
                    objNewIP = objMO.GetMethodParameters("EnableStatic")
                    objNewGate = objMO.GetMethodParameters
("SetGateways")
 
                    'Set DefaultGateway
                    objNewGate("DefaultIPGateway") = Gateway
 
                    'Dim x() As Integer = {1}
                    'objNewGate("GatewayCostMetric") = x
 
                    'Set IPAddress and Subnet Mask
                    objNewIP("IPAddress") = IPAddress
                    objNewIP("SubnetMask") = SubnetMask
 
                    objMO.InvokeMethod("EnableStatic", objNewIP, Nothing)
                    objMO.InvokeMethod("SetGateways", objNewGate, Nothing)
                    MessageBox.Show("Ip Updated")
                Catch ex As Exception
                    MessageBox.Show("Unable to Set IP : " + ex.Message)
                End Try
            End If
        Next
    End Sub
Merci d'avance de votre aide,

Amicalement,

Looney