Solved

Change Computer Name + Join Domain Through Batch File

Posted on 2004-08-06
39
33,355 Views
Last Modified: 2011-08-18
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.
0
Comment
Question by:EvilAardvark
  • 12
  • 11
  • 6
  • +4
39 Comments
 
LVL 10

Accepted Solution

by:
dis1931 earned 500 total points
ID: 11736254
Don't have the exact syntac in front of me....I believe you can use a tool that microsoft makes called netdom to add the computer to the domain.  As for changing the computer name I had to figure that out by myself but it can be done by changing 3 or 4 registry keys....I don't have my script in front of me...but I will Monday so if no one answers your question by then I can give you the specifics.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736515
Try this VB script and see if that will do the trick for you.

'On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

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")
0
 
LVL 14

Expert Comment

by:dlwyatt82
ID: 11736558
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
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736568
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.
0
 
LVL 14

Expert Comment

by:dlwyatt82
ID: 11736578
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.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736607
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736643
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.
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736663
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.
0
 
LVL 10

Expert Comment

by:dis1931
ID: 11736667
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.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736675
This will work with Windows 2000, you just need the netdom file from the Win2K3 ResKit.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736691
PS, almost all of the Win2K3 Reskit tools will work with older version of Windows.
0
 
LVL 10

Expert Comment

by:dis1931
ID: 11736792
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

0
 
LVL 51

Expert Comment

by:Netman66
ID: 11736858
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.

0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736876
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.
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736905
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.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736915
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.
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736947
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.  
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736965
netdom join machine /domain:domainname /userd:username /passwordd:password /reboot

Using netdom from XP. :) Should work on 2K machines as well.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Author Comment

by:EvilAardvark
ID: 11736981
machine = current computer name?
userd = username of user with privelege to join domain?
passwordd = password of said user?

Correct?

Just getting my syntax straight.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736982
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.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11736996
Yes, your syntax should be correct.
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11737011
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?
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11737037
Best place i found so far is:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11737144
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. :)
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11737389
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.
0
 
LVL 10

Expert Comment

by:dis1931
ID: 11737567
Did you try the one I sent you above Aardvark...that one should run on WIndows 2000.
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11737574
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.
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11737616
Sent via e-mail...
0
 
LVL 2

Author Comment

by:EvilAardvark
ID: 11737684
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?
0
 
LVL 10

Expert Comment

by:dis1931
ID: 11737920
Here are the keys you need to modify....then add to domain using netdom and you'll be all set.

\HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName
\HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName
\HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname
\HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname
0
 
LVL 7

Expert Comment

by:GATOR420
ID: 11738186
Try this for renaming:

http://www.willowhayes.co.uk/
0
 
LVL 51

Expert Comment

by:Netman66
ID: 11776311
netdom rename {machine} /Domain:domain /REBoot:time in seconds

Run this at the local PC.

0
 
LVL 51

Expert Comment

by:Netman66
ID: 11776332
Nevermind...for some stupid reason that is supposed to rename a DC?!!

0
 
LVL 10

Expert Comment

by:dis1931
ID: 12327397
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\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName
\HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName
\HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname
\HKLM\SYSTEM\CurrentControlSet\Services\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.
0
 
LVL 14

Expert Comment

by:Dhiraj Mutha
ID: 12772019
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\CurrentControlSet\Control\ComputerName\"
RegKeyTCPIP = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\"

Set WSHShell = CreateObject("WScript.Shell")

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\ComputerName", 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
0
 

Expert Comment

by:quicit
ID: 21475182
What if you were to ask a user (via .bat) what they wanted the computer name to be? How could that be done?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now