D
Don Quixote
Hello,
I use the code below to change the IP of a machine :
________________________________________________________________________
Private Sub ChangeIP(NewIP, NewMask)
Dim NetworkAdapter, AdapterConfiguration 'Objects
Dim IPAddress, SubnetMask, Gateway, DNS, strGatewayMetric 'String Arrays
Dim RetVal, x 'Integers
Dim NICname As String
Dim tmpIP As String
tmpIP = GetIPAddress()
Dim NetAdapterCFG As SWbemObjectSet
Dim naCFG As SWbemObject
NICname = ""
For x = 1 To lvwInterfaces.ListItems.Count
If lvwInterfaces.ListItems(x).Checked = True Then NICname =
lvwInterfaces.ListItems(x).SubItems(6)
Next x
If NICname = "" Then Exit Sub
Set NetAdapterCFG =
GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each naCFG In NetAdapterCFG
If UCase(naCFG.ServiceName) = UCase(NICname) Then
IPAddress = Array(NewIP)
SubnetMask = Array(NewMask)
RetVal = naCFG.enableStatic(IPAddress, SubnetMask)
If Not RetVal = 0 Then
MsgBox "Failure assigning IP/Subnetmask." & vbCrLf &
"Possible duplicate IP address", vbCritical, "Warning"
IPAddress = Array(tmpIP)
RetVal = naCFG.enableStatic(IPAddress, SubnetMask)
msgBox "Failure assigning IP/Subnetmask."
Else
Debug.Print NewIP
End If
End If
Next
End Sub
__________________________________________________________________
It works fine and as far pinging goes or accessing the net, it works
alright. I do have problems accessing shares on the local network though.
Let's say my address is 192.168.10.80, and I can access other PCs on the
network, if I change thru the code above my IP to 192.168.10.81, I don't
access anymore the PCs. I can still ping them and I can go on the net. That
means my gateway and DNS still work, right ?
Needless to say, if I do the changes thru the Windows applet, everything
works fine.
Anybody has an idea of what is at play here ?
Thx a million.
Sal
I use the code below to change the IP of a machine :
________________________________________________________________________
Private Sub ChangeIP(NewIP, NewMask)
Dim NetworkAdapter, AdapterConfiguration 'Objects
Dim IPAddress, SubnetMask, Gateway, DNS, strGatewayMetric 'String Arrays
Dim RetVal, x 'Integers
Dim NICname As String
Dim tmpIP As String
tmpIP = GetIPAddress()
Dim NetAdapterCFG As SWbemObjectSet
Dim naCFG As SWbemObject
NICname = ""
For x = 1 To lvwInterfaces.ListItems.Count
If lvwInterfaces.ListItems(x).Checked = True Then NICname =
lvwInterfaces.ListItems(x).SubItems(6)
Next x
If NICname = "" Then Exit Sub
Set NetAdapterCFG =
GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each naCFG In NetAdapterCFG
If UCase(naCFG.ServiceName) = UCase(NICname) Then
IPAddress = Array(NewIP)
SubnetMask = Array(NewMask)
RetVal = naCFG.enableStatic(IPAddress, SubnetMask)
If Not RetVal = 0 Then
MsgBox "Failure assigning IP/Subnetmask." & vbCrLf &
"Possible duplicate IP address", vbCritical, "Warning"
IPAddress = Array(tmpIP)
RetVal = naCFG.enableStatic(IPAddress, SubnetMask)
msgBox "Failure assigning IP/Subnetmask."
Else
Debug.Print NewIP
End If
End If
Next
End Sub
__________________________________________________________________
It works fine and as far pinging goes or accessing the net, it works
alright. I do have problems accessing shares on the local network though.
Let's say my address is 192.168.10.80, and I can access other PCs on the
network, if I change thru the code above my IP to 192.168.10.81, I don't
access anymore the PCs. I can still ping them and I can go on the net. That
means my gateway and DNS still work, right ?
Needless to say, if I do the changes thru the Windows applet, everything
works fine.
Anybody has an idea of what is at play here ?
Thx a million.
Sal