A
Allan Fog
Hi
My problem is that i want to rename or set the
computername before 1.st boot after a ghost clone
according to a plain text file containing a line for each
computer on the network where mac_adr + computername is
the key elements. i have the script below to join the
computer to the domain, but is it possible for me to set
the computername before joining the domain so that i dont
need to rename both the computer and the computer account
in the AD/domain. i would imagine something like set
objcomputer.computername = "####" where i replace
the "####" with the information from the textfile
containing computername & mac_adr.
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "MyDomain"
strPassword = "somepwd"
strUser = "someuser"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:
{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
_
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
Set Ws = WScript.CreateObject("Wscript.Shell")
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultDomainName","somedomain"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName",""
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultUserName",""
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AutoAdminLogon","0"
Sub ShutDown
nLogOff=0
nReboot=2
nForceLogOff=4
nForceReboot=6
nPowerDown=8
nForcePowerDown=12
Set oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery
("Select * from Win32_OperatingSystem")
For Each oOperatingSystem in oOS
oOperatingSystem.Win32Shutdown(nForcePowerDown)
Next
End sub
ShutDown
My problem is that i want to rename or set the
computername before 1.st boot after a ghost clone
according to a plain text file containing a line for each
computer on the network where mac_adr + computername is
the key elements. i have the script below to join the
computer to the domain, but is it possible for me to set
the computername before joining the domain so that i dont
need to rename both the computer and the computer account
in the AD/domain. i would imagine something like set
objcomputer.computername = "####" where i replace
the "####" with the information from the textfile
containing computername & mac_adr.
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "MyDomain"
strPassword = "somepwd"
strUser = "someuser"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:
{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
_
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
Set Ws = WScript.CreateObject("Wscript.Shell")
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultDomainName","somedomain"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName",""
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultUserName",""
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"
ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AutoAdminLogon","0"
Sub ShutDown
nLogOff=0
nReboot=2
nForceLogOff=4
nForceReboot=6
nPowerDown=8
nForcePowerDown=12
Set oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery
("Select * from Win32_OperatingSystem")
For Each oOperatingSystem in oOS
oOperatingSystem.Win32Shutdown(nForcePowerDown)
Next
End sub
ShutDown