#include <GUIConstants.au3>
#include <Array.au3>
Local $tabinput,$tabinput1,$tabinput2,$tabinput3,$tabinput4,$tabinput5,$tabcheck,$tabbutton1,$tabbutton2
Global $wbemFlagReturnImmediately = 0x1
Global $wbemFlagForwardOnly = 0x20
Global $strComputer = "localhost"
Opt("TrayAutoPause",0);当单击托盘图标时不暂停.
Opt("MouseCoordMode",0);相对激活窗口的坐标
Opt("WinTitleMatchMode",2);标题的任意子串皆可匹配
Opt("TrayMenuMode",1);托盘图标没有默认菜单
Opt("GUICloseOnESC",0);在按下 ESC 时不退出
$gui = GUICreate("IP设置", 400, 280)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$label = GUICtrlCreateLabel("说明"&@lf&" ----------------------------------"&@LF&"可以在此填写"&@LF&""&@LF&"你的内容",20, 20, 360, 130,0x01)
GUICtrlSetFont($label, 15, 400, 0, "隶书")
GUICtrlSetColor($label,0xff0000)
$tab = GUICtrlCreateTabItem("IP设置")
GUICtrlCreateGroup("网络地址", 20, 130, 360, 140)
GUICtrlSetState($tabinput,$GUI_ENABLE)
GUICtrlCreateLabel("IP 地 址:", 30, 160)
$tabinput1 = GUICtrlCreateInput("192.168.1.8", 90, 158, 100, 15)
GUICtrlCreateLabel("子网掩码:", 30, 180)
$tabinput2 = GUICtrlCreateInput("255.255.255.0", 90, 178, 100, 15)
GUICtrlCreateLabel("默认网关:", 30, 200)
$tabinput3 = GUICtrlCreateInput("192.168.1.1", 90, 198, 100, 15)
GUICtrlCreateLabel("首选 DNS:", 30, 220)
$tabinput4 = GUICtrlCreateInput("202.98.96.68", 90, 218, 100, 15)
GUICtrlSetState($tabinput4, $GUI_DISABLE)
GUICtrlCreateLabel("备用 DNS:", 30, 240)
$tabinput5 = GUICtrlCreateInput("61.139.2.69", 90, 238, 100, 15)
GUICtrlSetState($tabinput5, $GUI_DISABLE)
$tabcheck = GUICtrlCreateCheckbox("启用本地DNS", 238, 160)
$tabbutton1 = GUICtrlCreateButton("自动获取IP和DNS", 230, 190, 100, 25)
$tabbutton2 = GUICtrlCreateButton("设 置", 230, 220, 100, 25)
GUISetState(@SW_SHOW)
AdlibRegister($gui)
While 1
$msg=GUIGetMsg()
Select
Case $msg=$tabcheck And BitOR(GUICtrlRead($tabcheck),$gui_checked)=$gui_checked
GUICtrlSetState($tabinput4, $GUI_ENABLE)
GUICtrlSetState($tabinput5, $GUI_ENABLE)
Case $msg=$tabcheck And BitOR(GUICtrlRead($tabcheck),$gui_unchecked)=$gui_unchecked
GUICtrlSetState($tabinput4, $GUI_DISABLE)
GUICtrlSetState($tabinput5, $GUI_DISABLE)
Case $msg=$tabbutton1
GUICtrlSetState($tabbutton1,$GUI_DISABLE)
GUICtrlSetState($tabbutton2,$GUI_DISABLE)
RunWait(@ComSpec & ' /c netsh interface ip set dns name="本地连接" source=dhcp', '', @SW_HIDE)
RunWait(@ComSpec & ' /c netsh interface ip set address name="本地连接" source=dhcp', '', @SW_HIDE)
MsgBox(0,"IP设置","设置完成",10)
GUICtrlSetState($tabbutton1, $GUI_ENABLE)
GUICtrlSetState($tabbutton2, $GUI_ENABLE)
Case $msg = $tabbutton2
GUICtrlSetState($tabbutton1, $GUI_DISABLE)
GUICtrlSetState($tabbutton2, $GUI_DISABLE)
If GUICtrlRead($tabcheck) = $GUI_CHECKED Then
$tabinput4data = GUICtrlRead($tabinput4)
$tabinput5data = GUICtrlRead($tabinput5)
_DNS($tabinput4data, $tabinput5data)
EndIf
$tabinput1data=GUICtrlRead($tabinput1)
$tabinput2data=GUICtrlRead($tabinput2)
$tabinput3data=GUICtrlRead($tabinput3)
_SetIpAddress($tabinput1data, $tabinput2data, $tabinput3data)
MsgBox(0, "IP设置", "网络设置成功",10)
GUICtrlSetState($tabbutton1, $GUI_ENABLE)
GUICtrlSetState($tabbutton2, $GUI_ENABLE)
Case $msg=$gui_event_close
Exit
EndSelect
WEnd
Func _SetIpAddress($ipAdd, $Mask, $Gateway)
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =TRUE")
$ipAdd = _ArrayCreate($ipAdd)
$Mask = _ArrayCreate($Mask)
$Gateway = _ArrayCreate($Gateway)
$GatewayMetric = _ArrayCreate("1")
For $objItem In $colItems
$errEnable = $objItem.EnableStatic($ipAdd, $Mask)
$errGateways = $objItem.SetGateways($Gateway, $GatewayMetric)
Next
EndFunc
Func _DNS($DNS1, $DNS2)
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =TRUE", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$DNS = _ArrayCreate($DNS1, $DNS2)
If IsObj($colItems) Then
For $objItem In $colItems
$strDNSServerSearchOrder = $objItem.SetDNSServerSearchOrder ($DNS)
Next
Else
MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration")
EndIf
EndFunc