命令行改DNS存在一定的BUG,有时候不一定修改成功,论坛用户需要,我特别写了一个。
SETDNS.AU3
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=ip.ico
#AutoIt3Wrapper_Outfile=SETDNS.exe
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Comment=DNS修改工具
#AutoIt3Wrapper_Res_Description=DNS修改工具
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_LegalCopyright=TVZML作品
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
Break(0)
$g_Tray = "DNS修改工具"
If WinExists($g_Tray) = 1 Then Exit
AutoItWinSetTitle("DNS修改工具")
$dir = (@ScriptDir & "\DNS.ini")
$SectionNames = "配置信息"
_setip()
Exit
Func _setip() ;导入IP配置
If Not FileExists($dir) Then
MsgBox(16, "错误", "没有找到配置文件" & @CRLF & $dir, 3)
Exit
EndIf
$colItems = ""
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $SetDns[2]
$SetDns[0] = IniRead($dir, $SectionNames, "首选DNS", "")
$SetDns[1] = IniRead($dir, $SectionNames, "备用DNS", "")
TrayTip("", "正在设置DNS,请稍等...", 1)
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
For $objNetAdapter In $colItems
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
Next
EndIf
Exit
EndFunc ;==>_setip
配置文件样式
DNS.ini
[配置信息]
首选DNS=220.189.127.106
备用DNS=220.189.127.108