Link to home
Start Free TrialLog in
Avatar of Roebuck1967
Roebuck1967

asked on

What is the best possible way to rename computer names? I have 200 clients?

Perhaps a VB tool that will prompt me for the old computer name then the new one. Search the network and change the compute name.  Any ideas or methods?
Avatar of RDAdams
RDAdams
Flag of United States of America image

What OS are you using?
Is this a peer to peer or server to workstation network?
Avatar of Roebuck1967
Roebuck1967

ASKER

The OS is 2000
Unfortunately I have never seen an easy way to change the computer name.  Usually with large networks it is easier to set the computer name to the asset number and leave it alone.
With windows xp you can run a script to make the change.

http://www.microsoft.com/technet/community/scriptcenter/compmgmt/scrcm36.mspx
This is the bare bones of it.  We could add code to force a user to reboot, since the name change will occur only after that happens.  Also, how are you going to generate the computer names?  You could enter them all manually, or the script could prompt for an input box, or maybe we could figure out a way based on IP addres...  But you cant have duplicate names on your network.  Here's the code, which works by modifying the registry:

-----------------------------------------------------

sNewName = "HAPPYCOMPUTER"

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
.RegDelete sTcpipParamsRegPath & "Hostname"
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV HostName ", sNewName
End With
Actually, scratch that, use this code instead (for some reason, errors came up when I tried to delete the values):

---------------------------------------------

sNewName = "HAPPY COMPUTER"

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV HostName ", sNewName
End With
Hi YohanShminge does this work in Windows 2000 or only in XP?
YohanShminge,

To give you some more details we are going through an AD migration.  Will your script remove the old computer name from the domain? Also will the new computer name be added to the domain?
Oh, well AD changes things a bit... Let me get back to you on that one.  And just to set the record straight, the above script has an error in it.  "NV HostName " should be "NV HostName" - the extra space was screwing it up for 2000 for some reason.  But here it is in the working form:

sNewName = "NEWNAME"

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With
YohanShminge

We are still on NT but moving to AD.
Tired the script but nothing happens
I havent searched too hard, but I think RDAdams' link is closest to what you're looking for.  You could test it on Win2k just to see.  I'm not sure what would happen if you ran my script under AD, but I doubt it would work.  I found the perfect script earlier today, but for some reason I cant find it back.  I'll keep looking...its really frustrating me. :-(
Oh, well if you're not on AD yet, then we have a chance!  Nothing is supposed to happen when you run the script.  Its silent.  We can change that if you'd like.  Did you restart the computer after you ran the latest script?  Restart the computer after running the script then right-click My Computer and hit properties.  Click Network Identification and see if the name has been changed.  Make sure you change hte first line of the script so it corresponds to the name you want, like this:

sNewName = "COMPUTERNAME"
YahanShminge take a look at the script at the following site.  This might prompt your thought process.

How do you make this script work?  Do you need special software or can you just create a .bat file?

http://www.microsoft.com/technet/community/scriptcenter/compmgmt/scrcm36.mspx
YohanShminge

Hope I'm not asking too much.  

Can the script promt me "Old computer name?"  then "New computer name?"
Can the script run from my computer (admin priv) to rename & remove client on my network?

 
RDAdams,

I have looked at that script.  Unfortunately, I have no way to test it since I'm not currently running the active directory.  To make the script work, all you have to do is copy the code from the grey box into a text file, then save that text file as somename.VBS.  The VBS ending is key.  Then just double click the script to run it.

Roebuck1967, I have changed the script so it prompts the user for a new name only, but prompting for the old name would not be necessary, nor would the code be able to do anything with it.  As for running it from your computer, I don't think there is any way to do this.  It has to be run locally, because it changes the settings of the local machine.  You can configure it as a logon script so it runs automatically, and then the user could type in the name.  Alternately, we could work out some sort of naming convention that could choose a name automatically, perhaps reading names from a file on a server or something.  Could you give me an idea of how you're naming?

Here's the new code:

------------------------

sNewName = Inputbox("Please enter a new computer name:")

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With
I have a list of the new names in a excel spread sheet

All new names will have the following naming convention "TAKING-" followed by first five of last name and first two initials of first name. So Anthony Johnson would be = "TAKING-JohnsAn"
Sounds like we don't even need the spreadsheet.  We could just have the user enter their full name and parse that into substrings for the computer name.  How are they currently named? Is there any way to determine the user's name without having them enter it, or is there any way to link the current computer name with an entry in your excel file?
Most of the users logon using their first initial and full last name.  So Jill Davidson is JDavidson.
I considered using usernames as the trigger, but then that leaves two problems:
1) If the user happens to log onto a computer that is not theirs, that computer will be changed to the wrong name.
2) It doesnt quite fit your formula of first five letters of the last name plus the first two letters of the first name - you're missing the second letter of the first name, you the best you could do would be "TAKING-DavidJ"

Are the computer names in your excel spreadsheet names only or do they correspond to something we might get off the user's machine?
YohanShminge

Correction formula is first five letters of the last name plus the first (ONE) letter of the first name

Spread sheet has alll the old computer names, user ID's and new computer names.
OK, so its up to you what you want to do.  I would recommend reading from the excel file.  I believe that should be easy enough, but you'll have to locate the file on a dedicated server.  Excel will also need to be installed on every machine.  If it is not, you will need to export the Excel file as a CSV text file.  If you want to go with excel, I will also need to know the row and column numbers, and exactly how many usernames you have in the sheet, and I assume you're on sheet 1?
Reading from an excel file is fine. All my clients have it installed.
Everything is from sheet 1

Column A = Old Computer Name
Column E = New Computer Name

Also need it to run only Once not erverytime a user logs on. And it a log file could be stored on the server that would be great for tracking purposes.
OK, I shall work on that, but I don't have time right now... Perhaps tomorrow night
Thats fine...I really appreciate
OK, turns out I've got some free time ;-) I have created a script that will read from your excel file using VB automation.

Here's how it works:
First it runs through column A until it finds the computer's name, then it stores the value from the same row from column E into variable newName.
If it doesnt find its name, or finds the word "CHANGED" in column G, it quits the script.
Next, it stores the word "CHANGED" in column G, and the date and time in column H - this will act as your log file.  You can change the column values if you wish (they're numeric in the VBscript, rather than by letter), or if you dislike this method, we could always add more code to append to a separate text file on the server.
Then, once it has the name, the excel file is saved and closed and the code continues by changing the computer's name.
Once that is through, it displays a message box saying "Your computer name has been successfully changed to xxxxxx"
Let me know what you think!  I won't be around tomorrow morning.

-----------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "c:\CName.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If Trim(objSheet.cells(row, 1).Value) = CName Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Exit Do
        End If
    End If
row = row + 1
Loop

If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)
Thanks, I will try it out on Monday.

Question:

I assume I can call the vb script from a batch file correct?

What name should the excel spread sheet be?

Should the excel spread sheet reside in the same location as the vb script?

1) Yes, run this the same as the others
2) You can name it anything you like, but be sure to specify the correct name in line 6 (strPathExcel = "c:\CName.xls")
3) Again, the excel file can be located anywhere, but you must specify the full path to the network resource in line 6, along with the name, for example:
    strPathExcel = "\\Server\share\Sheetname.xls"
YohanShminge

Thanks for ALL your help.  I will test this out on Monday and let you know my results
YohanShminge

The script runs but the computer name is not changing.
- Not receiving message “Your computer name has been successfully changed to”
- Excel is not installed on the server but is on the client
In the spreadsheet
  Column A = Old Computer name
  Column B = Blank
  Column C = Users Name
  Column D = Blank
  Column E  = New Computer name

Script looks like this:

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If Trim(objSheet.cells(row, 1).Value) = CName Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Exit Do
        End If
    End If
row = row + 1
Loop

If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)


Does it give any error messages?  I assume you're running it on the clients to test? Not on the server? If run on the server, it will stop at the Excel part, since Excel is not installed locally.
No error messages.  Testing from a test box.  The script and excel spreadsheet are on the Domain Controller
OK, and the test box has Excel I assume?  Try this script and tell me what messages pop up (write them down, there could be as many as 9).  Also, make sure that the name in column A is different from the name in column B for this computer, and that this computers name is PRESENT in column A:

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Msgbox("Point 1")
Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Msgbox("Point 2")
CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Msgbox("Point 3")
Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If Trim(objSheet.cells(row, 1).Value) = CName Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            Msgbox("Already Changed")
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Msgbox("Point CHANGENAME FOUND Name: " + newName)
            Exit Do
        End If
    End If
row = row + 1
Loop

Msgbox("Point 4")
If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

Msgbox("Point 5")
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

Msgbox("Point 6")
sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"
Msgbox("Point 7")
With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)
Test box has excel installed
This is what I receive:

Pop up Box    Option
-----------------------------------
1 - Point 1     (select Ok)
2 - Point 2     (select Ok)
3 - Point 3     (select Ok)
4 - Point 3     (select Ok)
-----------------------------------

pops up 4 times
OK, this indicates to me that the program is not finding the computer's name in the excel sheet.  Try going through the sheet to make sure that this computer's name is listed in column A.  It would appear from the messages that it is not.  Another thing that could cause the problem is if you have blank rows anywhere before the end of the list.  The program stops moving through column A if it hits a blank cell.
For the fourth pop up box, you meant 4 - Point 4    (select Ok) right?
OK this is what I did.  The list has 420 names - I moved my test machine to the top of the list in column A.
made sure no blank rows existed.
Received the same 4 popup messages as above.
Computer name is still the same.
Should my columns have titles/labels?
No, there should be no titles/labels.  I forgot to take into account the case of the computer name.  Perhaps they are different.  Try this and tell me what happens:

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Msgbox("Point 1")
Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Msgbox("Point 2")
CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Msgbox("Point 3 - Current Name: " + CName)
Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If UCase(Trim(objSheet.cells(row, 1).Value)) = UCase(CName) Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            Msgbox("Already Changed")
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Msgbox("Point CHANGENAME FOUND Name: " + newName)
            Exit Do
        End If
    End If
row = row + 1
Loop

Msgbox("Point 4")
If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

Msgbox("Point 5")
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

Msgbox("Point 6")
sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"
Msgbox("Point 7")
With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)
1 - Point 1 (select Ok)
2 - Point 2 (select Ok)
3 - Point 3 "Current Name: TestAD" (select Ok)
4 - Point 4 "CHANGENAME FOUND Name: TAKING-Test01" (select Ok)
5 - Pount 4 (select Ok)
6 - Pount 6 (select Ok)
7 - Pount 7 (select Ok)
Your computer name has been succsssfully changed to TAKING-Test01

computer name was indeed changed
Excellent!  It must have been that the cases were different.  It just set them both to all uppercase to do the compare.
Next dilemma:
How do we eliminate all the error “point” messanges?
Since the computer name changed its no longer a recognized name on the network – any way the script could add it to the network and removed if possible the old name
YohanShminge, I enjoy watching the evolution of your script.  It has been a good training example.

Thanks.
Here it is without the messages.  What do you mean by "its no longer a recognized name on the network"?  Are you talking about AD?  If so, I'm not sure I can help with that...

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If UCase(Trim(objSheet.cells(row, 1).Value)) = UCase(CName) Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Exit Do
        End If
    End If
row = row + 1
Loop

If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)
Thanks RDAdams!
since the name is removed for the domain it cannot logon on the domain.  It has no domain affiilitation.
RDAdams

YohanShminge is tops in my book
Are you saying the new computer name assigned cannon logon to the domain?
That is correct


Error at logon says "systems computer account in its primary domain is missing or the password on the account is incorrect "
Any luck?
Calling Dr. YohanShminge
Calling Dr. YohanShminge
Hello everyone! I'm back! Wow, I think I've been having computer withdraw! ;-) So though I have no experience with the Active Directory, I may still be able to help.  I've heard good things about the "Active Directory Cookbook" and I found a script to add a computer to AD.  You'll have to fill in the stuff I don't know, but here is the code (not the ***********s):

-------------------------------------------------------

' From the book "Active Directory Cookbook" by Robbie Allen
' This VBScript code creates a computer object.
' ------ SCRIPT CONFIGURATION ------
Dim strComp
Set objNet = CreateObject("WScript.NetWork")

strBase = "<ParentComputerDN>"  '  **********I don't know what CN and DC are...hopfully you do! EX: cn=Computers,dc=rallencorp,dc=com

strComp = Trim(objNet.ComputerName) ' *********The computer name to be added

strDescr = ""      ' **********Enter a description for the computer here if you like!
' ------ END CONFIGURATION ---------

' ADS_USER_FLAG_ENUM
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000

set objCont = GetObject("LDAP://" & strBase)
set objComp = objCont.Create("computer", "cn=" & strComp)
objComp.Put "sAMAccountName", strComp & "$"
objComp.Put "description", strDesc
objComp.Put "userAccountControl", ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComp.SetInfo
Wscript.Echo "Computer account for " & strComp & " created"

Try that out by itself, and if it works, Ill add it into the main script.  Then I'll have to try and find a way to remove the old computer names.
Does this look right?

---------------------------------------------------------------------------------------------------------

Dim strComp
Set objNet = CreateObject("WScript.NetWork")

strBase = "<Would this be my Domain Name?>"  ' <-----------------------------------------------------

strComp = Trim(objNet.Taking-Test)

strDescr = "Test Computer"      ' **********Enter a description for the computer here if you like!
' ------ END CONFIGURATION ---------

' ADS_USER_FLAG_ENUM
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000

set objCont = GetObject("LDAP://" & strBase)
set objComp = objCont.Create("computer", "cn=" & strComp)
objComp.Put "sAMAccountName", strComp & "$"
objComp.Put "description", strDesc
objComp.Put "userAccountControl", ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComp.SetInfo
Wscript.Echo "Computer account for " & strComp & " created"
Also the domain controller is NT4 - we are not fully AD yet

Rather like this:

-----------------------------------------------------------------------
Dim strComp
Set objNet = CreateObject("WScript.NetWork")

strBase = "<Would this be my Domain Name?>"  ' <-----------------------------------------------------

strComp = Trim(objNet.Taking-Test)  <-----------------------------------------------------

strDescr = "Test Computer"   <-----------------------------------------------------
' ------ END CONFIGURATION ---------

' ADS_USER_FLAG_ENUM
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000

set objCont = GetObject("LDAP://" & strBase)
set objComp = objCont.Create("computer", "cn=" & strComp)
objComp.Put "sAMAccountName", strComp & "$"
objComp.Put "description", strDesc
objComp.Put "userAccountControl", ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComp.SetInfo
Wscript.Echo "Computer account for " & strComp & " created"
This line: strComp = Trim(objNet.Taking-Test)
Should be: strComp = "Taking-Test"

As for strBase, the example they gave was "cn=Computers,dc=rallencorp,dc=com" ... I was hoping you would know how to interpret this - something to do the AD, like the different catagories or something.

You say you're not fully AD? This script is for the Active Directory, so it might not work right.
Ran the script and getting an error at line 15 Char 1  Saying the server is not operational


Dim strComp
Set objNet = CreateObject("WScript.NetWork")

strBase = "<kcrg.com>"

strComp = "Taking-Test"

strDescr = "Test Computer"  

' ------ END CONFIGURATION ---------

' ADS_USER_FLAG_ENUM
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000

set objCont = GetObject("LDAP://" & strBase)
set objComp = objCont.Create("computer", "cn=" & strComp)
objComp.Put "sAMAccountName", strComp & "$"
objComp.Put "description", strDesc
objComp.Put "userAccountControl", ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComp.SetInfo
Wscript.Echo "Computer account for " & strComp & " created"
Yes, this must be because you're not running AD.  Can you describe exactly what you're using.  Do you know of any way to do this from the command line?
-Clients including test pc are all Windows 2000
-Domain Controller is Windows NT

No sure how to get around this via command line.
On your NT domain controller, perhaps you have the file, "netdom.exe" ?  What do you think of this: http://www.tburke.net/info/suptools/topics/netdom.htm
Sounds good as long as it works and does not to any damage.
I hope not!  Could you experiment with netdom and see if you can figure out the syntax it requires?
When running the Netdom - I'm able to add the computer to the domain but receive an error referencing the second line in the script below
(system cannon find path)


NETDOM ADD /d:kcrg.com Test01
/ud:kcrg.com\adminaccount /pd:*************
I believe those two should be on the SAME line in your BAT file, like this: NETDOM ADD /d:kcrg.com Test01 /ud:kcrg.com\adminaccount /pd:*************

Question: Is the netdom.exe file located on your win2k machines or only on the server?  If its only on the server, you could probably copy it to a shared folder, then you could add that line to a batch file, or to a VB script.  Is there also a NETDOM DELETE function? I assume you want to remove the old computer name...
The only problem with this is that you have put your administrative password out in the vbscript for anyone to read.  Perhaps you could create a separate domain admin account only for use in the script.
I was thinking the exact same thing.  The script will only run for a week then I can delete the account
There is a NETDOM REMOVE function that removes the computer fomr the domain.

I will try the same line option tomorrow and let you know.

THANKS for alll your help..If you every in Philly lunch is on me.
I'm always glad to help!  I hope to get a job doing this someday, but for now, its EE. ;-)
Receive this error when running the command from the same line

Multiple connections to a server or shared resource by the same user, using more
 than one user name, are not allowed. Disconnect all previous connections to the
 server or shared resource and try again..
On which computer? Have you disconnected any shares?
From my workstation
So your workstation was probably already part of the domain, right?  You probably cannot run that command multiple times.
are you saying that I sould run it from a pc that is not part of the domain.  The pc I'm adding from the script is not part of the domain, it's just a fictitious name.
Yeah, I think it will work only when run from a computer that is not part of the domain that has a real name.  If it works under those conditions, we can add it to that script, right after the part with all the registry name changes.

The first line of the command works as it did before - on the second line I get:
system cannot find path specified
Did you try putting them on the same line, like this: NETDOM ADD /d:kcrg.com Test01 /ud:kcrg.com\adminaccount /pd:*************
almost working -  get this error

The credentials supplied conflict with an existing set of credentials.

The command failed to complete successfully.
OK -- - - -THAT WORKED - What's the next step?
Paging Dr.  YohanShminge
Could you post the EXACT (remove the passwords of course ;-) syntax of the ADD and REMOVE functions?  Also, is netdom.exe on all of your 2000 machines?
netdom is not on any of my machines
the command goes as follows:

NETDOM ADD /d:kcrg.com Test-AD /ud:adminaccount /pd:*************
Any luck?
Don't worry, I haven't forgotten!  Here's the script including the netdom command to add computers, but not to remove the old names (edit the second to last line with the proper path to netdom.exe and the appropriate password:

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, strCN
Dim objFile, strGuyFile, intRow

Set objNet = CreateObject("WScript.NetWork")
Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

CName = Trim(objNet.ComputerName)
row = 1

newName = ""

Do While Trim(objSheet.cells(row, 1).Value) <> ""
    If UCase(Trim(objSheet.cells(row, 1).Value)) = UCase(CName) Then
        If Trim(objSheet.cells(row, 6)) = "CHANGED" Then
            objExcel.ActiveWorkbook.Close
            WScript.quit
        Else
            objSheet.cells(row, 6) = "CHANGED"
            objSheet.cells(row, 7) = Trim(CStr(Now))
            newName = Trim(objSheet.cells(row, 5).Value)
            Exit Do
        End If
    End If
row = row + 1
Loop

If newName = "" Then
    objExcel.ActiveWorkbook.Close
    WScript.quit
End If

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

sNewName = newName

Set oShell = CreateObject("WSCript.shell")

sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"

With oShell
'.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With

Set SH = CreateObject("WScript.Shell")
SH.Run "\\SERVERNAME\SHARENAME\NETDOM ADD /d:kcrg.com Test-AD /ud:adminaccount /pd:*************", 0, true

a = MsgBox("Your computer name has been successfully changed to " + sNewName, vbInformation)
Question

Should I still use Test-AD   (see below)      

SH.Run "\\DS\ADLookup\NETDOM ADD /d:kcrg.com Test-AD /ud:adminaccount /pd:*************", 0, true
O yes, i forgot about that! :-D Replace it with this line so it will ad the name it gets from the excel file:

SH.Run "\\SERVERNAME\SHARENAME\NETDOM ADD /d:kcrg.com " + sNewName + " /ud:adminaccount /pd:*************", 0, true
We are back to square one -
Error at logon says "systems computer account in its primary domain is missing or the password on the account is incorrect "
What was the condition of this computer before it was logged in and the script ran?  Part of the domain with an old name? When does this message appear?
Just a normal domain workstation (part of the domain)
Message appears when I reboot after the name change script runs
Did the name change? Did it rejoin the domain?
Yes the name changed and the new name is part of the domain.
found this error in the system event log

Event Type:      Error
Event Source:      Service Control Manager
Event Category:      None
Event ID:      7013
Date:            3/30/2004
Time:            4:58:58 PM
User:            N/A
Computer:      TAKING-Test3
Description:
Logon attempt with current password failed with the following error:
The trust relationship between this workstation and the primary domain failed.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
For each member, there is a discrete communication channel (that is, the secure channel) with a domain controller. The secure channel is used by the Netlogon service on the member and on the domain controller to communicate. The NETDOM command line utility makes it possible to reset the secure channel of the member.

Suppose you have a domain member named DOMAINMEMBER. You can reset the member secure channel by using the following command:
   NETDOM MEMBER \\DOMAINMEMBER /JOINDOMAIN
                        

You can run the command above on the member DOMAINMEMBER or on any other member or domain controller of the domain, provided that you are logged on with an account that has administrator access to DOMAINMEMBER.

The output received from the command should be similar to the following:
   Searching PDC for domain DOMAIN ...
   Found PDC \\DOMAINPDC
   Querying domain information on PDC \\DOMAINPDC ...
   Querying domain information on computer \\DOMAINMEMBER ...
   Computer \\DOMAINMEMBER is already a member of domain DOMAIN.
   Verifying secure channel on \\DOMAINMEMBER ...
   Verifying the computer account on the PDC \\DOMAINPDC ...
   Resetting secure channel ...
   Changing computer account on PDC \\DOMAINPDC ...
   Stopping service NETLOGON on \\DOMAINMEMBER .... stopped.
   Starting service NETLOGON on \\DOMAINMEMBER .... started.
   Querying user groups of \\DOMAINMEMBER ...
   Adding DOMAIN domain groups on \\DOMAINMEMBER ...

   The computer \\DOMAINMEMBER joined the domain DOMAIN successfully.

   Logoff/Logon \\DOMAINMEMBER to take modifications into effect.

Hmm, so can we include that line in the logon script?  DOMAINMEMBER Refers to the computer name, right?
Sounds like it
Yes, I think so too.  Can you logon to your test computer (the one currently giving the error) using the local Administrator account and try that command, to see if it remedies the problem?
Found a tool called RENCOMP

RenComp is a command line tool that helps Windows NT/2000 administrators to rename workstations’ names in a domain remotely from their terminal.
USAGE
RenComp.exe TargetComputer NewName
TargetComputer—The current name of the workstation that will be renamed.
NewName—The new name that will be given to the workstation. Should not be longer than 15 characters.
This tool copies itself to the \\TargetComputer\ADMIN$ share and installs itself as a service on the target workstation. Then it starts itself as a service on the workstation to change the name of the workstation and do a hard reboot of the workstation.
If the ADMIN$ share does not exist on the target workstation, then RenComp tries to create it. If the ADMIN$ share didn’t exist prior to the running of RenComp, it is later removed from the workstation.
Only administrators can install services, and therefore, only administrators can run RenComp.
Wow, does it work?
Where did you find the tool RENCOMP?  Is this a commercial tool?
It allows admins to remotely rename the computers.
RDAdams someone from my company gave it to me.
basically your run it and once the client reboots their pc is part of the domain with new computer name - it does not remove the old name though and you have to do each pc 1 at a time
If you do Help > About does it have a website or manufacturer name?  I would like to take a look at it!
Well, each computer has to be physically turned on, and you wouldnt want to do this without warning the computer's user first (which you could do through the "net send" command).  However, once you have that done, its a simple matter of writting a VBscript to loop through that excel sheet and rename all the computers.
YohanShminge
ok lets give it a shot
RDAdams

The company is Aleita Software
ASKER CERTIFIED SOLUTION
Avatar of YohanShminge
YohanShminge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That will loop through all the old names in the sheet and run RENCOMP with the old name and the new name listed in the sheet.  If you don't want to click 420 messageboxes, you could remove the   a = MsgBox("Changed " + CName + " to " + newName + "!", vbInformation) line from the script.  Also, you could change this line:
SH.Run "RENCOMP " + CName + " " + newName, 0, true
To this, to allow you to see what RENCOMP is doing:
SH.Run "RENCOMP " + CName + " " + newName, 1, true
Where shoud I place RENCOMP.EXe file?
Just for anyone else following this discussion, you can download the Domain Migration Resource kit which has the RENCOMP utility as part of the kit from the following website.

http://www.aelita.com
Almost gave me a heart attack – the script started to go down the lookup chart and rename each machine – I received a pop up confirmation for each one. I stopped it on the 2nd entry.  When the test pc rebooted it had the same old name – It did change one users pc which I will check when she takes her lunch break.
I'm sorry about that!  So the test machine did NOT get its name changed?  Had you manually changed it back since my original script changed it?  If you terminated that script early, you might have to terminate "EXCEL.EXE" in the processes list of the machine that ran it before it will work again.  As for where to place the RENCOMP file, it should be located in your system directory, or you'll have to specify the entire path.  I'll bet that the script actually DIDNT run RENCOMP, unless you had placed it in one of these locations, and it was just giving the messageboxes.  Try this instead, so you can be sure that rencomp runs:

--------------------------------------------------------------------------------------------------------

Dim objExcel, strPathExcel, objFile

Set objExcel = CreateObject("Excel.Application")
strPathExcel = "\\DS\ADLookup\ADLookupR.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
Set SH = CreateObject("WScript.Shell")

row = 1

newName = ""

Do While Trim(objSheet.cells(row, 1).Value) <> ""
   CName = objSheet.cells(row, 1)
   objSheet.cells(row, 6) = "CHANGED"
   objSheet.cells(row, 7) = Trim(CStr(Now))
   newName = Trim(objSheet.cells(row, 5).Value)
   
   SH.Run "RENCOMP " + CName + " " + newName, 1, true

   a = MsgBox("Changed " + CName + " to " + newName + "!", vbInformation)
 
   row = row + 1
Loop

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
Thats ok just gave me a scare.  Test machine still have the same name "TestPC"
The RENCOM file is located on the Domain Controller whre my script files are.
OK, can you move RENCOMP into your windows or system directory?  Then, try to run it manually, without the script, like this:

"RENCOMP TestPC newName"

Replacing newName with the new name for the test PC.  If you can get it to work from DOS, then it should work in the script...
A few things here:

1) In order to run RENCOMP you must be an administrator

2) RENCOMP will only run from its location - so you can't place it in a windows dir. unless you run it from that location.

3) Once it runs it automatically reboots the pc.


1) Do you mean that the person logged on at the remote computer must be an admin?

2) Thats fine, we'll just specify the full path in the script

3) This is a necessary evil - all you can do is notify the user.
1 The account that runs the utility mut be an admin

3 Yep....

1) Too bad you demoted all accounts to Power User a couple weeks ago...

Any ideas?
Nope...they are stilll Admins
Hey the script that we ran that scared me actually worked on her machine.  Whe she rebooted she was able to login fine with the new computer name.
Really?  Thats great!  So I guess the only problem is having the computers on and notifying the user.  You could either plan a time after everyone leaves and just tell them to leave their computers on, or we could have the vbscript send a notification via email or the "net send" command...
Actually the user would not have to know... The last script ran and the user was able to work fine - had no clue the computer name changed.

So if we could get the script to run from my test box - and log the change that would be great.
Strange...I thought the program would force a hard restart after the name change?

So you want the script to run from your test box?  It should run without any trouble.  It already logs the changes to the excel file in columns F and G, as long as the script completely executes and the excel file is saved and closed.  If you want it to log to a separate text file, that would be fine too!
Me too - the existing spreadsheet is fine
Any luck?
I lost track of what you want me to do... I thought you were testing on your test box?
Sorry about the confusion; I have the script running and reduced the lookup table to 6 entries.  It tells me the name was changed even for pc's that are turned off... Not sure why.
Yeah, I was thinking that RENCOMP would give an error if that happened, but I guess not, so the script just keeps going as if it had worked.  Im not sure if theres a way to get the output from it or not.  Do you know where I could download the program?
No sure where to download RENCOM software...Wish I could email it to you.
Remove spaces and change (at) to @: falcon10 (at) attbi.com
Thanks, My name is Paul.  I will send you a test from my home account (Verizon)
YohanShminge

Let close this case and I will give you the Points - We can open a new onw where I can ask some additional questions about this script.  Is that ok?
Yes, thats fine - it was getting exceedingly long anyways!
Did you get my email?
Started a new continuation of this issue..Look it up when you have a chance
Will do - you probably know my schedule by now! ;-)
Yes...I will send the application now from my work email address