wmi修改DNS,为什么不成功附源码
#NoTrayIcon#include <Array.au3>
Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $strComputer = "localhost"
Global $colItems = ""
Local $DNS
$DNS = "61.177.7.1"
$DNS = "221.228.255.1"
_DNS($DNS, $DNS)
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;==>_DNS 我这边测试可以修改
如果你那不得行的话可以看看下面这些能不能帮到你的
通过注册表修改IP,IPX,机器名,DNS 那就郁闷了,不知道注册表改的成功率是不是100% DNS修改以前用WMI修改好像感觉不好用,后来就用注册表修改了,改完刷新就可以生效了。。
IP修改得用WMI或API,要不不好立即生效,如果只是注册表修改,好像得重启才生效的。。
页:
[1]