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