MadMax0843
New member
- Joined
- Jun 26, 2015
- Messages
- 1
- Programming Experience
- Beginner
Hey guys, new to vb and hoping I could get some help. This code does not cause any problems in my program in windows xp and windows 7 but will not work on windows 8. Every time I try to change the adapter in Windows 8 I get the error: "Unable to set IP: arithmetic operation resulted in overflow." Does anyone know what I am doing wrong?
VB.NET:
Dim IPAddress As String = TextBoxIPAddress.Text Dim SubnetMask As String = TextBoxSubnetMask.Text
Dim Gateway As String = TextBoxGateway.Text
Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMOC As ManagementObjectCollection = objMC.GetInstances()
If ComboBoxAdapterSelector.SelectedIndex < 0 Then
MsgBox("Please, select an adapter.")
Else
Me.Cursor = Cursors.WaitCursor
For Each objMO As ManagementObject In objMOC ' iterate through adapters
If (Not CBool(objMO("IPEnabled"))) Then
Continue For
End If
Dim nResult As Integer
Dim strAdapaterName As String = objMO("Description").ToString
If strAdapaterName = ComboBoxAdapterSelector.Text Then ' found adapter we selected
Try
Dim objNewIP As ManagementBaseObject = Nothing
Dim objSetIP As ManagementBaseObject = Nothing
Dim objNewGate As ManagementBaseObject = Nothing
Dim objSetGate As ManagementBaseObject = Nothing
objNewIP = objMO.GetMethodParameters("EnableStatic")
'Set IPAddress and Subnet Mask
objNewIP("IPAddress") = New String() {IPAddress}
objNewIP("SubnetMask") = New String() {SubnetMask}
objSetIP = objMO.InvokeMethod("EnableStatic", objNewIP, Nothing)
nResult = objSetIP("returnValue")
If nResult <> 0 Then
MessageBox.Show(ErrorMessageEnableStatic(nResult))
End If
objNewGate = objMO.GetMethodParameters("SetGateways")
'Set DefaultGateway
objNewGate("DefaultIPGateway") = New String() {Gateway}
objNewGate("GatewayCostMetric") = New Integer() {1}
objSetGate = objMO.InvokeMethod("SetGateways", objNewGate, Nothing)
nResult = objSetGate("returnValue")
If nResult <> 0 Then
MessageBox.Show(ErrorMessageEnableStatic(nResult))
End If
'objSetIP = objMO.InvokeMethod("SetGateways", objNewGate, Nothing)
'nResult = objSetIP("returnValue")
'If nResult <> 0 Then
' MessageBox.Show(ErrorMessageSetGateWays(nResult))
'End If
Console.WriteLine("Updated IPAddress, SubnetMask and Default Gateway!")
Catch ex As Exception
MessageBox.Show("Unable to Set IP : " & ex.Message)
End Try
Exit For
End If
Next objMO
End If