#41532 - 2003-06-16 06:47 PM
Re: Change DNS
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
This is part of my change DNS/DHCP script.
I only post the DNS part for Win98/Me.
Examples of use:
Example 1: The PC is part of subnet '10.1' and has only one DNS server: 10.1.1.10
code:
ChgDNS98Me('10.1',Split(10.1.1.10))
Example 2: The PC is part of subnet '10.1.1' and has 2 DNS servers: 10.1.1.10 and 10.1.1.11
code:
ChgDNS98Me('10.1.1',Split(10.1.1.10 10.1.1.11))
code:
Function ChgDNS98Me($SubNet,$DNS) Dim $Changed,$NICs,$NIC,$i,$Key $Changed = 0 $NICs = ArrayEnumKey('HKLM\Enum\Network\MSTCP') For $i = 0 To UBound($NICs) $NICs[$i] = ReadValue('HKLM\Enum\Network\MSTCP\' + $NICs[$i],'Driver') Next For Each $NIC In $NICs $Key = 'HKLM\System\CurrentControlSet\Services\Class\' + $NIC If ReadValue($Key,'DriverDesc') = 'TCP/IP' $IPAdr = ReadValue($Key,'IPAddress') If IsInNet('$IPAdr',$SubNet) $Key = 'HKLM\System\CurrentControlSet\Services\VxD\MSTCP' $Changed = WriteReg($Key,'NameServer',Join($DNS,','),'REG_SZ',$Changed) EndIf EndIf Next If $Changed $RC = MessageBox('Your network settings have been changed.' + @CRLF + 'Please reboot the PC','Please reboot the PC',48) EndIf EndFunction Function ArrayEnumKey($Key) If Not KeyExist($Key) $ArrayEnumKey = '' Return EndIf $i = 0 $SubKey = EnumKey($Key,$i) While @Error = 0 ReDim Preserve $ArrayEnumKey[$i] $ArrayEnumKey[$i] = $SubKey $i = $i + 1 $SubKey = EnumKey($Key,$i) Loop EndFunction Function IsInNet($IP, $SubNet) Dim $ChkNet,$ChkIP,$i If '$IP' = '' Or $IP = '0.0.0.0' Return EndIf $ChkNet = Split($SubNet,'.') $ChkIP = Split($IP,'.') For $i = 0 To UBound($ChkNet) If $ChkNet[$i] <> $ChkIP[$i] Return EndIf Next $IsInNet = 1 EndFunction Function WriteReg($Key,$ValueName,$Value,$Type,$Changed) Dim $Dif $Dif = 0 If '' + ReadValue($Key,$ValueName) <> $Value $Dif = 1 EndIf If '' + ReadType($Key,$ValueName) <> $Type $Dif = 1 EndIf If $Dif $RC = WriteValue($Key,$ValueName,$Value,$Type) EndIf $WriteReg = $Changed | $Dif EndFunction
Because this is a part of my original code you should test it before use.
-Erik [ 16. June 2003, 18:56: Message edited by: kholm ]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|