#41529 - 2003-06-16 01:30 PM
Change DNS
|
leno
Fresh Scripter
Registered: 2002-09-18
Posts: 30
|
i need to change the DNS address in win98 through script ( more than 200 pc's ) . dows someone knows how ?
|
|
Top
|
|
|
|
#41531 - 2003-06-16 02:40 PM
Re: Change DNS
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Tsk. That sounds like yoou don't use DHCP, do you ? If not consider to make one of your Servers a DHCP Server. And in the mean time :
quote: WriteValue( )
Action: Creates a new key, adds another value-name to an existing key (and assigns it a value), or changes the value of an existing value-name. Syntax: WriteValue ("subkey", "entry", "expression", "data type") Parameters: Subkey Identifies the subkey where you want to write a value entry.
Entry
The name of the entry. To write to the (default) entry of a key, specify an empty string as the entry name ("").
Expression
The data to store as the value of the entry.
REG_MULTI_SZ (multi-string) variables are returned with the pipe symbol ( | ) used as the separator between strings. If a string contains a pipe symbol character, it is represented by two pipe symbol characters ( || ).
Data type
Identifies the data type of the entry. The following data types are supported: REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD REG_DWORD_LITTLE_ENDIAN REG_DWORD_BIG_ENDIAN REG_LINK REG_MULTI_SZ REG_RESOURCE_LIST REG_FULL_RESOURCE_DESCRIPTOR Returns: 0 Value successfully written Error code Function failed Remarks: If the registry key that you are attempting to write a value to does not exist, it will be automatically created. See Also: AddKey( ), DelKey( ), DelTree( ), ReadType( ), ReadValue( ) Example: $RC=WriteValue("EZReg\Test", "A MultiString variable", "Line 1|Line 2|Line 3 with a || in it|" "REG_MULTI_SZ") If @ERROR = 0 ? "Value written to the registry" Endif
If you do have an active DHCP Server :
Edit Scope/Global Option 006 - DNS Server [ 16. June 2003, 14:42: Message edited by: Jochen ]
_________________________
|
|
Top
|
|
|
|
#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.
|
|
|