Windows Scripting BLOG

Due to limited time working on this project this place is not intended to people who are new to scripting but much more for people who are already familiar with the VBS/WMI syntax.

Donnerstag, 17. Mai 2007

Set DNS Suffix + other related DNS settings

On Error Resume Next
Const FULL_DNS_REGISTRATION =True
Const DOMAIN_DNS_REGISTRATION = False
strKeyPath1 = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
strEntryName1 = "SyncDomainWithMembership"
strEntryName2 = "UseDomainNameDevolution"
strEntryName3 = "NV Domain"
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath="SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
strEntryName = "RegistrationEnabled"
dwValue = 1
dwValue2 = "YOURSUFFIX"
IN_FILE = Wscript.Arguments(0)
Const PRO_READ = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(IN_FILE, PRO_READ)
strComputers = objFile.ReadAll
objFile.ClosearrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers Set objWMILocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMICimService = objWMILocator.ConnectServer(strComputer, "root\cimv2")
Set colOS = objWMICimService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOS
if ( InStr(1, objOS.Caption, "XP", vbTextCompare) > 0 ) Then isWinXP = true else isWinXP = false End if
NextSet objReg = GetObject _ ("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv")
Set colNetCards = objWMICimService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
if (isWinXP) Then retVal = objReg.SetDWORDValue (HKEY_LOCAL_MACHINE, strKeyPath & objNetCard.SettingID, strEntryName, dwValue)
retVal = objReg.SetDWORDValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName1, dwValue)
retVal = objReg.SetDWORDValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName2, dwValue )
retVal = objReg.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName3, dwValue2 )
Else retVal = objNetCard.SetDynamicDNSRegistration (FULL_DNS_REGISTRATION, DOMAIN_DNS_REGISTRATION)
retVal = objReg.SetDWORDValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName1, dwValue)
retVal = objReg.SetDWORDValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName2, dwValue)
retVal = objReg.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath1, strEntryName3, dwValue2)
End if
if retVal <> 0 then Wscript.Echo "Error Setting DNS Config at Computer: "& strComputerElse Wscript.Echo "Successfully Changed the required settings on Computer: "& strComputer
end if
Next
Next
'created by Julian Ruf

Keine Kommentare: