Does anyone have any suggestions to make this more elegant? It pulls the
Dns Suffix Search Order from the registry and compares it to 'DnsSuffixes'
which should be there by default. If the user already has additional
suffixes, it adds them to the back-end of the string and then puts it back
into the registry.

Thanks,
Rob Boger



'> DNS Suffix Search Order.

Function SetDnsSuffixes(Computer)
Dim RegistryObject, CurrentDnsSuffixes, DnsSuffixes, NewDnsSuffixes,
WshShell
Set RegistryObject =
GetObject("WinMgmts:{impersonationLevel=impersonate}!\\" & Computer &
"\root\default:StdRegProv")

'> Define Dns Suffix Search Order.
DnsSuffixes = Array("my.domain.com", _
"domain.com", _
"sbc.com")

'> Get Current Dns Suffix Search Order.
RegistryObject.GetStringValue &H80000002, _
"System\CurrentControlSet\Services\TCPIP\Parameters",
"SearchList", CurrentDnsSuffixes
CurrentDnsSuffixes = Split(CurrentDnsSuffixes,",")

'> Compare Dns Suffixes.
For J = 0 To Ubound(DnsSuffixes)
For I = 0 To Ubound(CurrentDnsSuffixes)
If Ucase(CurrentDnsSuffixes(I)) = Ucase(DnsSuffixes(J))
Then
CurrentDnsSuffixes(I) = ""
End If
Next
NewDnsSuffixes = NewDnsSuffixes & DnsSuffixes(J)
If J <> Ubound(DnsSuffixes) Then
NewDnsSuffixes = NewDnsSuffixes & ","
End If
Next

'> Add Existing Dns Suffixes.
For I = 0 To Ubound(CurrentDnsSuffixes)
If CurrentDnsSuffixes(I) <> "" Then
NewDnsSuffixes = NewDnsSuffixes & "," &
CurrentDnsSuffixes(I)
End If
Next

'> Update Dns Suffixes.
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite
"HKLM\System\CurrentControlSet\Services\TCPIP\Parameters\SearchList", _
NewDnsSuffixes, "REG_SZ"

End Function

Re: DnsDomainSuffixSearchOrder. by Rob

Rob
Sat Feb 07 06:08:31 CST 2004

I got it slimmed down a little bit:

'> DNS Suffix Search Order.

Function SetDnsSuffixes(Computer)
Dim CurrentDnsSuffixes, DnsSuffixes, NewDnsSuffixes, RegistryKey,
WshShell
Set WshShell = CreateObject("Wscript.Shell")

'> Define Variables.
RegistryKey = "HKLM\System\CurrentControlSet\Services" & _
"\TCPIP\Parameters\SearchList"
DnsSuffixes = Array("my.domain.com", _
"domain.com", _
"sbc.com")

'> Get Current Dns Suffix Search Order.
CurrentDnsSuffixes = Split(WshShell.RegRead(RegistryKey),",")

'> Compare Dns Suffixes.
For J = 0 To Ubound(DnsSuffixes)
For I = 0 To Ubound(CurrentDnsSuffixes)
If Ucase(CurrentDnsSuffixes(I)) = Ucase(DnsSuffixes(J))
Then
CurrentDnsSuffixes(I) = ""
End If
Next

NewDnsSuffixes = NewDnsSuffixes & DnsSuffixes(J)
If J <> Ubound(DnsSuffixes) Then
NewDnsSuffixes = NewDnsSuffixes & ","
End If
Next

'> Add Existing Dns Suffixes.
For I = 0 To Ubound(CurrentDnsSuffixes)
If CurrentDnsSuffixes(I) <> "" Then
NewDnsSuffixes = NewDnsSuffixes & "," &
CurrentDnsSuffixes(I)
End If
Next

'> Update Dns Suffixes.
WshShell.RegWrite RegistryKey, NewDnsSuffixes, "REG_SZ"

End Function