EvilAardvark
asked on
Change Computer Name + Join Domain Through Batch File
I currently am going through the process of upgrading quite a few computers from windows 98 to 2000. We're cross-trading, so I give person A a new computer, and take their old one, and set it up with 2000 for person B, so that no person is left without a computer. This means I can't use the same computer names that the new and old computers use because we cant have 2 of the same name on the domain.
What I want to be able to do is change the computer name (and then reboot, putting a second batch file in HKEY...RunOnce) and use the second batch file to join the computer to our domain, essentially making this process unattended (like the rest of my windows 2000, upgrades, and software install). I have the means to either determine what computer name to use or to prompt for a computer name, that's no problem. I just want to know if there's a net command or some other type of command that will change my computer's name through a batch file. I have no problems using .reg files as well.
If you could provide me with the syntax for any such commands, i would appreciate it. I'm offering 200 points if you can tell me how to change the computer name through batch file/reg file, and 300 if you can tell me how to join the domain.
What I want to be able to do is change the computer name (and then reboot, putting a second batch file in HKEY...RunOnce) and use the second batch file to join the computer to our domain, essentially making this process unattended (like the rest of my windows 2000, upgrades, and software install). I have the means to either determine what computer name to use or to prompt for a computer name, that's no problem. I just want to know if there's a net command or some other type of command that will change my computer's name through a batch file. I have no problems using .reg files as well.
If you could provide me with the syntax for any such commands, i would appreciate it. I'm offering 200 points if you can tell me how to change the computer name through batch file/reg file, and 300 if you can tell me how to join the domain.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The windows XP version of the netdom.exe utility allows you to perform both actions. See knowledgebase article http://support.microsoft.com/default.aspx?scid=kb;en-us;298593&sd=tech
That's what the above script above uses, netdom.exe. If you don't have it, you will need it in order to run the script.
The script Gator posted includes the syntax for using the XP netdom.exe - "netdom renamecomputer" etc. In order for that script to work, you'll need to make sure you obtain the correct version of netdom - the one included with the Windows 2000 resource kit doesn't contain the "RenameComputer" option.
Just download the Windows 2003 ResKit from Microsoft here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
ASKER
That netdom looks alright, but like i said, and like the title of this TA is, I'm looking for windows 2000.
Plus, i searched around and couldn't find anywhere to download that netdom.exe file.
I was wondering if there's any way, WITHOUT KNOWING the current computer name to do that netdom thing. I suppose if i change the computer name first, and store the new name, i can use that. I use * for the computer name during unattended install, so it's always a string of pseudo-random numbers.
If you could find me a working link to that netdom.exe for windows 2000 that i can use to join the domain, i'd appreciate it. Also, i'd prefer to use the registry key edit to change computer name. If someone could show me that, please.
Plus, i searched around and couldn't find anywhere to download that netdom.exe file.
I was wondering if there's any way, WITHOUT KNOWING the current computer name to do that netdom thing. I suppose if i change the computer name first, and store the new name, i can use that. I use * for the computer name during unattended install, so it's always a string of pseudo-random numbers.
If you could find me a working link to that netdom.exe for windows 2000 that i can use to join the domain, i'd appreciate it. Also, i'd prefer to use the registry key edit to change computer name. If someone could show me that, please.
ASKER
Due to the intricacies of our domain, it is imperative that i reboot the computer after changing the computer name, and then join the domain. I can't do both at the same time, i've tried. I'd prefer to be able to use a registry key to change the computer name (as it would save me time in having to look up the current computer name), and then reboot, and use that netdom to connect to the domain.
So really, the only functionality i need in netdom is to join the domain. If you could link me to the windows 2000 version i'd appreciate it.
So really, the only functionality i need in netdom is to join the domain. If you could link me to the windows 2000 version i'd appreciate it.
There are a few registry entries that control the name of the computer and can be changed without knowing the name of the PC. Also I believe netdom can only change the computer name if it is on the domain already...not if it has not yet joined the domain...at least that was what i remember from when i was trying to do this.
This will work with Windows 2000, you just need the netdom file from the Win2K3 ResKit.
PS, almost all of the Win2K3 Reskit tools will work with older version of Windows.
You can find the Windows 2000 version here...it is under a weird name but it is a zip white a word doc and the netdom tool......
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=3EDA5A79-C99B-4DF9-823C-933FEBA08CFE
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=3EDA5A79-C99B-4DF9-823C-933FEBA08CFE
Windows 98 does not use a computer account for the Domain - since it has no SAM.
Simply remove it from the LAN, and join the new Windows 2000 to the domain with the same name.
As long as you don't connect the 98 box back on the LAN before changing it's name there will be no NetBIOS conflict.
The only thing to watch for is if you run WINS. You'll need to delete the PC name from there and let the new one repopulate WINS.
Simply remove it from the LAN, and join the new Windows 2000 to the domain with the same name.
As long as you don't connect the 98 box back on the LAN before changing it's name there will be no NetBIOS conflict.
The only thing to watch for is if you run WINS. You'll need to delete the PC name from there and let the new one repopulate WINS.
ASKER
Gator, while most of those things may work, it won't INSTALL without having XP or higher.
So that link is no good. I'll try the 2000 version.
So that link is no good. I'll try the 2000 version.
ASKER
Can someone tell me the syntax for netdom to JUST have it join the domain?
That's all i want it to do, no renaming. If someone could show me the registry keys to edit for changing the name (while not on the domain), i'd appreciate it.
That's all i want it to do, no renaming. If someone could show me the registry keys to edit for changing the name (while not on the domain), i'd appreciate it.
Umm, as far as I know I can install the 2003 ResKit on a 98 machine if I want. Just some of the tools may not work because 98 isn't the supported operating system to use the tools. Windows NT, 2000, 2003, and XP are.
ASKER
I JUST ran that file you linked to. "You must have at least Windows XP to continue."
Setup fails.
I'm just letting you know what happened TO ME. It doesn't help me that YOUR 98 computer can install it, but MY 2000 machine CAN NOT. I have no reason to be lying to you. If i say it didn't work, it didn't work.
Setup fails.
I'm just letting you know what happened TO ME. It doesn't help me that YOUR 98 computer can install it, but MY 2000 machine CAN NOT. I have no reason to be lying to you. If i say it didn't work, it didn't work.
netdom join machine /domain:domainname /userd:username /passwordd:password /reboot
Using netdom from XP. :) Should work on 2K machines as well.
Using netdom from XP. :) Should work on 2K machines as well.
ASKER
machine = current computer name?
userd = username of user with privelege to join domain?
passwordd = password of said user?
Correct?
Just getting my syntax straight.
userd = username of user with privelege to join domain?
passwordd = password of said user?
Correct?
Just getting my syntax straight.
Hmm.. Sorry about that. That's a new thing. :(
Try using the syntax above for Netdom Win2K version. The syntax I am using I don't believe is new to the 2K3 version.
Try using the syntax above for Netdom Win2K version. The syntax I am using I don't believe is new to the 2K3 version.
Yes, your syntax should be correct.
ASKER
Sounds good, now if someone could tell me what registry keys handle the current computer name?
In other words, what keys do i need to modify?
In other words, what keys do i need to modify?
ASKER
Best place i found so far is:
HKEY_LOCAL_MACHINE\SYSTEM\ ControlSet 001\Contro l\Computer Name\Activ eComputerN ame
HKEY_LOCAL_MACHINE\SYSTEM\
Yes, but you will find several of those.
I think if you try to rename it by just putting in some registry keys you might have SID problems. But I'll be happy to wait for your results. :)
I think if you try to rename it by just putting in some registry keys you might have SID problems. But I'll be happy to wait for your results. :)
ASKER
Maybe you could send me your netdom.exe file (webmaster@ktcomx.com), and i'll use that one? If you say the individual files are platform-independant, i'll believe you, but the install itself won't run on my computer.
Did you try the one I sent you above Aardvark...that one should run on WIndows 2000.
ASKER
yeah, but i need something as well that can change my computer name..
Yours is fine for getting the domain, but the computername needs to be changed first.
Yours is fine for getting the domain, but the computername needs to be changed first.
Sent via e-mail...
ASKER
no good. Says i don't have the right dlls. :(
So still, i'm stuck without a way to change computer name. I SUPPOSE i could do that part manually, but i'd really rather not. Anyone else able to help me?
So still, i'm stuck without a way to change computer name. I SUPPOSE i could do that part manually, but i'd really rather not. Anyone else able to help me?
Here are the keys you need to modify....then add to domain using netdom and you'll be all set.
\HKLM\SYSTEM\CurrentContro lSet\Contr ol\Compute rName\Acti veComputer Name\Compu terName
\HKLM\SYSTEM\CurrentContro lSet\Contr ol\Compute rName\Comp uterName\C omputerNam e
\HKLM\SYSTEM\CurrentContro lSet\Servi ces\Tcpip\ Parameters \Hostname
\HKLM\SYSTEM\CurrentContro lSet\Servi ces\Tcpip\ Parameters \NV Hostname
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
netdom rename {machine} /Domain:domain /REBoot:time in seconds
Run this at the local PC.
Run this at the local PC.
Nevermind...for some stupid reason that is supposed to rename a DC?!!
I think I answered this question, netdom as mentioned can be used to add a computer to the domain. Obviously the computer name needs to be changed first before it can be added to domain. Netdom comes with instructions and if you type netdom /? you will get all switches of all possibilities however all that is needed is the netdom join function. The first portion of how to change the name on a PC can be done through the four registry keys:
\HKLM\SYSTEM\CurrentContro lSet\Contr ol\Compute rName\Acti veComputer Name\Compu terName
\HKLM\SYSTEM\CurrentContro lSet\Contr ol\Compute rName\Comp uterName\C omputerNam e
\HKLM\SYSTEM\CurrentContro lSet\Servi ces\Tcpip\ Parameters \Hostname
\HKLM\SYSTEM\CurrentContro lSet\Servi ces\Tcpip\ Parameters \NV Hostname
These keys can be changed through a batch file using regedit and a variable that can be passed in upon user entry or hardcoded as needed. All that is needed is a batch file and the use of regedit to change these keys. The way i created it was to ask the user for a variable appended to end of batch file....So let's say that the batch file was called rename.bat then it would need to be passed the computer name...so the command would be "rename.bat PC1". Then this variable would be used in the batch file to automaticaly generate a .reg file and subsequently run the .reg file and delete the .reg file. Then it would have to run netdom to join to the domain. Then you can make netdom reboot automatically after completion. I had it setup to prompt for the admin password but that can be hard coded into the batch just be careful where you leave the batch as the password will be in clear text.
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
\HKLM\SYSTEM\CurrentContro
These keys can be changed through a batch file using regedit and a variable that can be passed in upon user entry or hardcoded as needed. All that is needed is a batch file and the use of regedit to change these keys. The way i created it was to ask the user for a variable appended to end of batch file....So let's say that the batch file was called rename.bat then it would need to be passed the computer name...so the command would be "rename.bat PC1". Then this variable would be used in the batch file to automaticaly generate a .reg file and subsequently run the .reg file and delete the .reg file. Then it would have to run netdom to join to the domain. Then you can make netdom reboot automatically after completion. I had it setup to prompt for the admin password but that can be hard coded into the batch just be careful where you leave the batch as the password will be in clear text.
Try this script i think it works
Dim RegKeyCompName, RegKeyTCPIP, WSHShell, ComputerName, HostName, DomainName, FQDN, ADRootDSE, ADSysInfo, ADComputerName, ADRenameOK, ADRNewName, vStartRenameCA, NewNAmeU, NewNameL, vStartRenameAD
On Error Resume Next
'###### READ IN EXISTING COMPUTERNAME AND FQDN ######
RegKeyCompName = "HKLM\SYSTEM\CurrentContro lSet\Contr ol\Compute rName\"
RegKeyTCPIP = "HKLM\SYSTEM\CurrentContro lSet\Servi ces\Tcpip\ Parameters \"
Set WSHShell = CreateObject("WScript.Shel l")
ComputerName = WSHShell.RegRead (RegKeyCompName & "ComputerName\ComputerName ")
Hostname = WSHShell.RegRead (RegKeyTCPIP & "Hostname")
DomainName = WSHShell.RegRead (RegKeyTCPIP & "Domain")
FQDN = HostName & "." & DomainName
Set ADRootDSE = GetObject("LDAP://RootDSE" )
If Err.Number <> 0 then
ADComputerName = "Unable to determine this information"
ADOU = "Unable to determine this information"
ADRenameOK = "0"
else
Set ADSysInfo = CreateObject("ADSystemInfo ")
ADComputerName = ADSysInfo.ComputerName 'Get DN of local computer
ADRenameOK = "1"
ADOU = Mid(ADComputerName, InStr(ADComputerName, "=") + 1) 'Strip off just after the first = sign
ADOU = Mid(ADOU, InStr(ADOU, "=") - 2) 'Strip off at 2 before the second = sign
ComputerPath = "LDAP://" & ADComputerName
OUPath = "LDAP://" & ADOU
End if
'###### ASK USER FOR NEW DETAILS ###########
MsgBox "This script renames this computer and its active directory account" & vbCr & vbCr & "Name: " & ComputerName & vbCr & "FQDN: " & FQDN & vbCr & vbCr & "AD DN: " & ADComputerName & vbCr & "AD OU: " & ADOU, 0, "Information"
NewName = InputBox("Enter the new computer name below and click OK to continue","Rename: Step 1")
NewNameU = UCase(NewName)
NewNameL = LCase(NewName)
NewNameUCN = "CN=" & NewNameU
if NewName = "" then
wscript.echo "The computer name has not been changed"
else
vStartRenameCA = MsgBox ("Continue and rename computer to: " & NewName,vbYesNo or vbExclamation,"Rename: Step 2")
if vStartRenameCA = 6 then
With WSHShell
.RegDelete RegKeyTCPIP & "Hostname"
.RegDelete RegKeyTCPIP & "NV Hostname"
.RegWrite RegKeyCompName & "ComputerName\ComputerName ", NewNameU
.RegWrite RegKeyCompName & "ActiveComputerName\Comput erName", NewNameU
.RegWrite RegKeyTCPIP & "Hostname", NewNameL
.RegWrite RegKeyTCPIP & "NV Hostname", NewNameL
End With
wscript.echo "The computer name and FQDN have been changed"
elseif vStartRenameCA = 7 then
wscript.echo "The computer name and FQDN have NOT been changed"
end if
if ADRenameOK = 1 then
vStartRenameAD = MsgBox ("Continue and rename AD Account to: " & NewName,vbYesNo or vbExclamation,"Rename: Step 3")
if vStartRenameAD = 6 then
Set objItem = GetObject(ComputerPath)
objItem.Put "dNSHostName", NewNameL & DomainName
objItem.SetInfo
objItem.Put "displayName", "DESKTOP_" & NewNameU & "$"
objItem.SetInfo
objItem.Put "sAMAccountName", NewNameU & "$"
objItem.SetInfo
Set objNewOU = GetObject(OUPath)
Set objMoveComputer = objNewOU.MoveHere _
(ComputerPath, NewNameUCN)
wscript.echo "The active directory computer account has been changed"
elseif vStartRenameAD = 7 then
wscript.echo "The computer account in AD has NOT been changed"
End If
else
wscript.echo "Insufficient information to rename AD account"
End If
End if
Dim RegKeyCompName, RegKeyTCPIP, WSHShell, ComputerName, HostName, DomainName, FQDN, ADRootDSE, ADSysInfo, ADComputerName, ADRenameOK, ADRNewName, vStartRenameCA, NewNAmeU, NewNameL, vStartRenameAD
On Error Resume Next
'###### READ IN EXISTING COMPUTERNAME AND FQDN ######
RegKeyCompName = "HKLM\SYSTEM\CurrentContro
RegKeyTCPIP = "HKLM\SYSTEM\CurrentContro
Set WSHShell = CreateObject("WScript.Shel
ComputerName = WSHShell.RegRead (RegKeyCompName & "ComputerName\ComputerName
Hostname = WSHShell.RegRead (RegKeyTCPIP & "Hostname")
DomainName = WSHShell.RegRead (RegKeyTCPIP & "Domain")
FQDN = HostName & "." & DomainName
Set ADRootDSE = GetObject("LDAP://RootDSE"
If Err.Number <> 0 then
ADComputerName = "Unable to determine this information"
ADOU = "Unable to determine this information"
ADRenameOK = "0"
else
Set ADSysInfo = CreateObject("ADSystemInfo
ADComputerName = ADSysInfo.ComputerName 'Get DN of local computer
ADRenameOK = "1"
ADOU = Mid(ADComputerName, InStr(ADComputerName, "=") + 1) 'Strip off just after the first = sign
ADOU = Mid(ADOU, InStr(ADOU, "=") - 2) 'Strip off at 2 before the second = sign
ComputerPath = "LDAP://" & ADComputerName
OUPath = "LDAP://" & ADOU
End if
'###### ASK USER FOR NEW DETAILS ###########
MsgBox "This script renames this computer and its active directory account" & vbCr & vbCr & "Name: " & ComputerName & vbCr & "FQDN: " & FQDN & vbCr & vbCr & "AD DN: " & ADComputerName & vbCr & "AD OU: " & ADOU, 0, "Information"
NewName = InputBox("Enter the new computer name below and click OK to continue","Rename: Step 1")
NewNameU = UCase(NewName)
NewNameL = LCase(NewName)
NewNameUCN = "CN=" & NewNameU
if NewName = "" then
wscript.echo "The computer name has not been changed"
else
vStartRenameCA = MsgBox ("Continue and rename computer to: " & NewName,vbYesNo or vbExclamation,"Rename: Step 2")
if vStartRenameCA = 6 then
With WSHShell
.RegDelete RegKeyTCPIP & "Hostname"
.RegDelete RegKeyTCPIP & "NV Hostname"
.RegWrite RegKeyCompName & "ComputerName\ComputerName
.RegWrite RegKeyCompName & "ActiveComputerName\Comput
.RegWrite RegKeyTCPIP & "Hostname", NewNameL
.RegWrite RegKeyTCPIP & "NV Hostname", NewNameL
End With
wscript.echo "The computer name and FQDN have been changed"
elseif vStartRenameCA = 7 then
wscript.echo "The computer name and FQDN have NOT been changed"
end if
if ADRenameOK = 1 then
vStartRenameAD = MsgBox ("Continue and rename AD Account to: " & NewName,vbYesNo or vbExclamation,"Rename: Step 3")
if vStartRenameAD = 6 then
Set objItem = GetObject(ComputerPath)
objItem.Put "dNSHostName", NewNameL & DomainName
objItem.SetInfo
objItem.Put "displayName", "DESKTOP_" & NewNameU & "$"
objItem.SetInfo
objItem.Put "sAMAccountName", NewNameU & "$"
objItem.SetInfo
Set objNewOU = GetObject(OUPath)
Set objMoveComputer = objNewOU.MoveHere _
(ComputerPath, NewNameUCN)
wscript.echo "The active directory computer account has been changed"
elseif vStartRenameAD = 7 then
wscript.echo "The computer account in AD has NOT been changed"
End If
else
wscript.echo "Insufficient information to rename AD account"
End If
End if
What if you were to ask a user (via .bat) what they wanted the computer name to be? How could that be done?
'On Error Resume Next
'open the file system object
Set oFSO = CreateObject("Scripting.Fi
set WSHShell = wscript.createObject("wscr
Dim sNewCname 'Variable to hold Computer Name you enter in the inputbox
Dim sOldCname 'computers current name
'First param is message text, second is message title
sOldCname = InputBox("Enter computers current name","Windows 2k3 Netdom Rename Script")
sNewCname = InputBox("Enter computers new name","Windows 2k3 Netdom Rename Script")
Call WSHShell.Run("cmd.exe /c NETDOM RENAMECOMPUTER " & sOldCname & " /newname:" & sNewCname & " /userd:DOMAIN\user /passwordd:test /usero:admin /passwordo:password /f /reboot:45")