Monday, April 4, 2011

VB Script to Set the Default Domain for Computers in a text file

The following script Sets the Default Domain at login for computers in C:\temp\computers.txt

' Change Registry Keys so the default domain name is BOB when  people login
Const HKEY_LOCAL_MACHINE = &H80000002

' Read Arguments from a Text File
Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "Set Login Domain to BOB Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
 
      WScript.Echo objDictionary.Item(objItem)
      strComputer = objDictionary.Item(objItem)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "DefaultDomainName"
strValue = "BOB"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "CachePrimaryDomain"
strValue = "BOB"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops have had Default Domain Set!"
End if 

No comments:

Post a Comment