How to rename large numbers of XP systems

  • Thread starter Thread starter Sandy Wood
  • Start date Start date
S

Sandy Wood

Our network has over 900 XP systems that we need to rename. We're looking for
a way to script or otherwise automate the process. We need to change a single
character in the computer name to remove an underscore and replace it with a
dash. We believe we can vbscript a search and replace script but beyond that
have only begun to look into the process. Has anyone done anything like this
before without physically visiting each system?
 
Sandy Wood said:
Our network has over 900 XP systems that we need to rename. We're looking
for
a way to script or otherwise automate the process. We need to change a
single
character in the computer name to remove an underscore and replace it with
a
dash. We believe we can vbscript a search and replace script but beyond
that
have only begun to look into the process. Has anyone done anything like
this
before without physically visiting each system?

Below is an untested script I found in this newsgroup some
time ago. With a bit of tweaking it could do the job for you -
if it works! Alternatively you could try netdom.exe. Remember
that renaming each PC is only half the job - you also have to
rejoin it to your domain.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

strcomputer = InputBox("Enter New Computer Name")

If strComputer = "" then
Wscript.quit
End If

For Each objComputer in colComputers
err = objComputer.Rename(strComputer)
Next

'Joining a computer to a domain
'=========================
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 = InputBox("Enter Domain name to Join")
strUser = InputBox("Enter Domain User to join domain")
strPassword = Inputbox("Enter password")

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, _
"cn=Computers,DC=mydomain,dc=com", JOIN_DOMAIN + ACCT_CREATE)

If ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error.
Proceeding to change computer name. "
Else
MsgBox "Computer not added to domain successfully. Return value: " &
ReturnValue
End If
 
Peruse this and you should find something you like.


Website:

Change computer name and add to the domain (VB Script)
http://en.allexperts.com/q/VB-Script-2351/Change-computer-name-add.htm


Batch file:

reg update "hkcr\clsid\{20d04fe0-3aea-1069-a2d8-08002b30309d}\localizedstring=My
Computer %%computername%%" reg_expand_sz


A full VBS file:

; Renaming of Computer's Name using VBScript

Option Explicit

Dim Text, Title
Dim WshNetwork ' Object variable
Text = "Networking information" & vbCrLf & vbCrLf
Title = "Rename Hostname?"

' Create a new WshNetwork object to access network properties.
Set WshNetwork = WScript.CreateObject("WScript.Network")

Text = Text & "Computer name : " & WshNetwork.ComputerName & vbCrLf
Text = Text & "Domain : " & WshNetwork.UserDomain & vbCrLf
Text = Text & "User name : " & WshNetwork.UserName & vbCrLf & vbCrLf
Text = Text & "Do you want to rename this computer?"

If MsgBox(Text, vbYesNo + vbQuestion, Title) = vbyes Then
Dim strComputerName, objWMIService, objComputer, returnCode

strComputerName = InputBox("Enter a new machine name for this computer:",
"Rename Computer")

If strComputerName <> "" Then

Set objWMIService = GetObject("Winmgmts:root\cimv2")

' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")
ReturnCode = objComputer.Rename(strComputerName)
Next
If ReturnCode <> 0 Then
MsgBox "There was a problem changing the computer name. System error code :
" & ReturnCode
Else
If MsgBox("Changes made. Do you wish to restart the computer?", vbYesNo +
vbQuestion, Title) = vbyes Then
objShell.Run "rundll32 shell32.dll,SHExitWindowsEx 2", 1, False
Else
MsgBox "You must restart computer for changes to take effect"
End If
End If
End If
End If


ju.c
 
More!


Windows 2000 Unattended Installations and related utilities
http://www.willowhayes.co.uk/
http://www.willowhayes.co.uk/download/compname.exe

Compname.exe is a utility to dynamically generate and set the computer name at the command line.


How to change computername
http://groups.google.co.uk/group/mi...admin/msg/c2523370d044e7b3?dmode=source&hl=en

quote/
Compname.exe is a utility to generate a computer name to your
specifications, optionally pulling in data including asset tag/serial
number from the chassis, motherboard and system, System UUID/GUID, mac
address, IP address octets, date, and a random element.

The program should run fine on all Windows platforms since Windows 95,
including Windows NT. If available (i.e 2000, XP, .net) the program
will call SetComputerNameExA from kernel32.dll. If this function is
not available, it calls SetComputerNameA from the same DLL. This
ensures that, for 2000 and above, the DNS host name and the NetBIOS
name both get set properly.

Download the utility and type "compname.exe /?" to get the syntax.
It's pretty easy.

For example,

"compname.exe /c jupiter" sets the computer name to jupiter
"compname.exe /c PC-?k-?l" will use the IP address. If the IP address
is 192.168.1.100, the name will be "PC-1-100"
"compname.exe /c pc-?s" sets the machine to "pc-abcdef" where abcdef
is the SMBIOS asset tag/serial number.
"compname.exe /c pc-?9" generates a name including nine random
characters.

The program can also be used for reading any of these fields (by using
the /d[isplay] option), or for piping these numbers into other
applications.

"compname.exe /s" will give you a summary of the SMBIOS, IP and MAC
information.

Any comments, bug reports or suggestions for improvements are very
welcome.
/quote

ju.c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top