Hallo,
Ich habe nach langem suchen endlich brauchbaren Code zum ändern der Netzwerkeinstellungen gefunden. Aber leider wird hier für jede Netzwerkkarte die IP geändert. Ich möchte aber nur Lan haben. Wie kann ich zum beispiel nur die IP vom Adapter 1 ändern ?
Die Adapter werden ja hier gescant:
win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each oCard In oResult
With oCard
Allerdings sehe ich keine Id wenn ich an der stelle eine Stopmarke benutze.
_________________________________________________________
Private Sub Form_Load()
Dim lStatus As Long
Dim vMsgBoxStyle As VbMsgBoxStyle
lStatus = ChangeIP(„192.168.0.5“)
Select Case lStatus
Case 0, 1
vMsgBoxStyle = vbInformation
Case Else
vMsgBoxStyle = vbCritical
End Select
MsgBox GetStatus(lStatus), vMsgBoxStyle
End Sub
Private Function ChangeIP(ByVal sNewIP As String, _
Optional ByVal sGateway As String = „192.168.0.254“, _
Optional ByVal sDNSServer As String = „192.168.0.254“, _
Optional ByVal sSubNetMask As String = „255.255.255.0“) As Long
Dim oWMI As Object
Dim oResult As Object
Dim oCard As Object
Dim nStatus As Long
Set oWMI = GetObject(„winmgmts:“)
Set oResult = oWMI.ExecQuery(„SELECT * FROM win32_NetworkAdapterConfiguration WHERE IPEnabled = True“)
For Each oCard In oResult
With oCard
If IsArray(.IPAddress) Then
ChangeIP = .EnableStatic(Array(sNewIP), Array(sSubNetMask))
.SetGateways Array(sGateway)
'If you want to set the MTU uncomment the following line
'.SetMTU Array(„1500“)
.SetDNSServerSearchOrder Array(sDNSServer)
End If
End With
Next
End Function
Private Function EnableDHCP() As Long
Dim oWMI As Object
Dim oResult As Object
Dim oCard As Object
Dim nStatus As Long
Set oWMI = GetObject(„winmgmts:“)
Set oResult = oWMI.ExecQuery(„SELECT * FROM win32_NetworkAdapterConfiguration WHERE IPEnabled = True“)
For Each oCard In oResult
With oCard
If IsArray(.IPAddress) Then
EnableDHCP = .EnableDHCP
End If
End With
Next
End Function
Private Function GetStatus(lStatus As Long) As String
Select Case lStatus
Case 0
GetStatus = „Successful completion, no reboot required.“
Case 1
GetStatus = „Successful completion, reboot required.“
Case 64
GetStatus = „Method not supported on this platform.“
Case 65
GetStatus = „Unknown failure.“
Case 66
GetStatus = „Invalid subnet mask.“
Case 67
GetStatus = „An error occurred while processing an instance that was returned.“
Case 68
GetStatus = „Invalid input parameter.“
Case 69
GetStatus = „More than five gateways specified.“
Case 70
GetStatus = „Invalid IP address.“
Case 71
GetStatus = „Invalid gateway IP address.“
Case 72
GetStatus = „An error occurred while accessing the registry for the requested information.“
Case 73
GetStatus = „Invalid domain name.“
Case 74
GetStatus = „Invalid host name.“
Case 75
GetStatus = „No primary or secondary WINS server defined.“
Case 76
GetStatus = „Invalid file.“
Case 77
GetStatus = „Invalid system path.“
Case 78
GetStatus = „File copy failed.“
Case 79
GetStatus = „Invalid security parameter.“
Case 80
GetStatus = „Unable to configure TCP/IP service.“
Case 81
GetStatus = „Unable to configure DHCP service.“
Case 82
GetStatus = „Unable to renew DHCP lease.“
Case 83
GetStatus = „Unable to release DHCP lease.“
Case 84
GetStatus = „IP not enabled on adapter.“
Case 85
GetStatus = „IPX not enabled on adapter.“
Case 86
GetStatus = „Frame or network number bounds error.“
Case 87
GetStatus = „Invalid frame type.“
Case 88
GetStatus = „Invalid network number.“
Case 89
GetStatus = „Duplicate network number.“
Case 90
GetStatus = „Parameter out of bounds.“
Case 91
GetStatus = „Access denied.“
Case 92
GetStatus = „Out of memory.“
Case 93
GetStatus = „Already exists.“
Case 94
GetStatus = „Path, file, or object not found.“
Case 95
GetStatus = „Unable to notify service.“
Case 96
GetStatus = „Unable to notify DNS service.“
Case 97
GetStatus = „Interface not configurable.“
Case 98
GetStatus = „Not all DHCP leases could be released or renewed.“
Case 100
GetStatus = „DHCP not enabled on adapter.“
End Select
End Function