k3eper
asked on
Change Name then join Domain VBS
Ok this script changes the computer name to the service tag from bios (Dell machines) im trying to get it to join domain after but its not doing it. It completes with restart etc but it jsut doesnt seem to join domain. There are no errors that it reports. Anyone got any ideas? If i manually try join domain using the credentials in the script it works fine.
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> "" Then exit For
Next
Set ws = WScript.CreateObject("WScript.Shell")
value1 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"
value2 = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\"
ws.RegWrite value1 & "ComputerName", strSN
ws.RegWrite value2 & "NV Hostname", strSN
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "DOMAINNAMEHERE"
strPassword = "PASSWORDHERE"
strUser = "USERNAMEHERE"
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)
wshshell.run "shutdown /r"
Set WSHShell = Nothing
WScript.Quit(0)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See this as well. It's pretty much the exact method you are using, but at MSDN they too do the JOIN_DOMAIN+ACCT_CREATE
http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx
Pber we are twins !!! :-)
sorry didn't refresh the page
sorry didn't refresh the page
(:
ASKER
Great thanks works like a charm
ReturnValue = objComputer.JoinDomainOrWo
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN)
to
ReturnValue = objComputer.JoinDomainOrWo
strPassword, strDomain & "\" & strUser, NULL, _
JOIN_DOMAIN + ACCT_CREATE)