本帖最後由 rictirse 於 2014-5-22 22:03 編輯
- #include <GuiConstantsEx.au3>
- #include <GuiIPAddress.au3>
- #include <WindowsConstants.au3>
- #include <Array.au3>
- Opt ( "GUIOnEventMode", 1)
- Dim $Cnt = 5
- Dim $hIPAddress[$Cnt]
- Dim $Test[$Cnt] = [ "IP Address", "Subnet Mask", "GateWay", "DNS 1", "DNS 2"]
- Dim $ini = @ScriptDir&"IPList.ini"
- $hgui = GUICreate ( " IP Switch", 195, 240, Default, Default, 1)
- GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit")
- For $i = 0 To ($Cnt-1)
- GUICtrlCreateLabel ( $Test[$i], 10, 24+($i*30), 65)
- $hIPAddress[$i] = _GUICtrlIpAddress_Create ( $hgui, 75, 20+($i*30), 100, 20)
- _GUICtrlIpAddress_Set ( $hIPAddress[$i], IniRead ( $ini, "IP Address", "IP_Address"&$i, ""))
- Next
- GUICtrlCreateButton ( "Start", 30, 175, 60,25)
- GUICtrlSetOnEvent ( -1, "_Start")
- GUICtrlCreateButton ( "Exit", 100, 175, 60,25)
- GUICtrlSetOnEvent ( -1, "_Exit")
- GUISetState ()
- While True
- For $i = 0 To ($Cnt-1)
- _Save( $hIPAddress[$i], "IP_Address"&$i)
- Next
- Sleep (50)
- WEnd
- Func _Save($hIPAddress, $iniName)
- $ipData = _GUICtrlIpAddress_Get($hIPAddress)
- If $ipData = 0 Then Return
- If $ipData <> IniRead ( $ini, "IP Address", $iniName, "") Then
- IniWrite ( $ini, "IP Address", $iniName, $ipData)
- EndIf
- EndFunc
- Func _Start()
- Local $InterFace="區域連線"
- Local $IPX = '00004444'
- Local $IpADD = _GUICtrlIpAddress_Get($hIPAddress[0])
- Local $SubMask = _GUICtrlIpAddress_Get($hIPAddress[1])
- Local $GateWay = _GUICtrlIpAddress_Get($hIPAddress[2])
- Local $DNS1 = _GUICtrlIpAddress_Get($hIPAddress[3])
- Local $DNS2 = _GUICtrlIpAddress_Get($hIPAddress[4])
- _WMI_SetNetworkAdapterInfo( $InterFace, $IpADD, $SubMask, $GateWay, $DNS1, $DNS2, $IPX)
- MsgBox ( 0, "", "完成")
- EndFunc
- Func _Exit()
- Exit
- EndFunc
- Func _WMI_SetNetworkAdapterInfo($HostName, $IpADD, $SubMask, $GateWay, $DNS1, $DNS2, $IPX)
- Dim $SetDns[2], $SetIPAddress[1], $SetSubnetmask[1], $SetGateway[1]
- $SetDns[0] = $DNS1
- $SetDns[1] = $DNS2
- $SetIPAddress[0] = $IpADD
- $SetSubnetmask[0] = $SubMask
- $SetGateway[0] = $GateWay
- Local $objWMIService = ObjGet("winmgmts:\localhostrootCIMV2")
- Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
- Local $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
- Local $objNetworkSettings = $objWMIService.Get("Win32_NetworkAdapterConfiguration")
- For $objNetAdapter In $colComputers
- $objNetAdapter.Rename($HostName)
- Next
- If IsObj($colItems) Then
- For $objNetAdapter In $colItems
- $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
- $objNetAdapter.SetGateways($SetGateway)
- $objNetAdapter.SetDNSServerSearchOrder($SetDns)
- Next
- EndIf
- $objNetworkSettings.SetIPXVirtualNetworkNumber($IPX)
- EndFunc
複製代碼 |