Код:
$aCompList = _NetServerEnum(1)
$sDNSList = "192.168.1.1,192.168.1.2"
For $i=1 To $aCompList[0]
_NetAdapterSetDNS($sDNSList, $aCompList[$i])
Next
Func _NetAdapterSetDNS($sDNSList, $sHostName = "localhost")
Local $objWMIService = ObjGet( "winmgmts:\\"& $sHostName &"\root\CIMV2")
Local $aDNSList = StringSplit($sDNSList, ",;|", 2)
Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True', "WQL", 0x30)
If IsObj($colItems) Then
For $colItem In $colItems
$colItem.SetDNSServerSearchOrder($aDNSList)
Return True
Next
EndIf
Return False
EndFunc ;==> _NetAdapterSetDNS
Func _NetServerEnum ($iSrvType = -1, $sDomain = '')
Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1]=[0], $i
Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
Local $uString = DllStructCreate("char[16]")
Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
If Not ($sDomain='' Or $sDomain='*') Then
DllStructSetData($uDomain, 1, StringToBinary($sDomain,2))
$pDomain = DllStructGetPtr($uDomain)
EndIf
Local $ret = DllCall ("netapi32.dll", "int", "NetServerEnum", _
"ptr", 0, "int", 100, _
"ptr", DllStructGetPtr($uBufPtr,1), "int", -1, _
"ptr", DllStructGetPtr($uBufPtr,2), _
"ptr", DllStructGetPtr($uBufPtr,3), _
"int", $iSrvType, "ptr", $pDomain, "int", 0 )
If $ret[0] Then Return SetError(1, $ret[0], '')
Local $res[DllStructGetData($uBufPtr,3)+1]=[DllStructGetData($uBufPtr,3)]
For $i=1 To DllStructGetData($uBufPtr,3)
Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr,1)+($i-1)*$iRecLen)
Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord,2))
DllStructSetData($uString,1,BinaryToString(DllStructGetData($sNBName,1),2))
$res[$i] = DllStructGetData($uString,1)
Next
$ret = DllCall ("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr,1))
Return $res
EndFunc ; ==> _NetServerEnum
|