WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Changing Computer Name and Machine Account Name

Keywords: 	  Changing Computer Name and Machine Account Name 

Question:

I need to add a two character prefix to all existing machine names on our domain, ie: from TS238383 to 38TS238383

I've had some previous experience with WinBatch, but this far exceeds my past efforts.

Answer:

This will be a 2 part exercise. One part will change the local workstation name on the computer. The second part will have to change the name of the machine account for the newly renamed workstation. Please note that machine accounts [a.k.a. computer accounts] only exist for NT platform family systems such as WinNT/2K/XP, but not for Win9x/ME systems.

Use the IntControl(76,...) function call to change the computer name. This change won't take effect until the computer has been rebooted.

Note that if you change the workstation name and change the name on the domain controller (the PDC), this doesn't immediately re-sync with the BDC. So if the workstation does not connect to the PDC, then it won't resync automatically, even after a reboot. To force a re-sync, use the wntDomainSync function.

Use the wntUserRename() function in the NT extender to rename the machine account. Remember that machine accounts are hidden [e.g. they have a trailing "$" in the name] and they are are always in lowercase.

Remember that you must have appropriate rights in order to set the computer name and to rename the computer's machine account in the domain.

More specifically:

You will need to write the script so that it will get the name of the computer on which it is running, store the value in a variable, place "38" in front of the name through string concatenation, set the new computer name on the workstation and then perform the rename operation on the PDC. This can all be done in the script provided that it is running while logged on as a user who has both local workstation administrator rights as well as domain administrator rights and has network access while being run on a workstation by SMS.

To get the name of the computer, you can either get the value of the "COMPUTERNAME" environment variable [on WinNT/2K/XP only], or you can read it from the registry [works in all cases].

ComputerName = Environment('COMPUTERNAME')
or
ComputerName = RegQueryValue(@REGMACHINE,"System\CurrentControlSet\Control\ComputerName\ComputerName[ComputerName]")
After you have the current computer name, FOR YOUR PARTICULAR SITUATION put "38" on the beginning as follows:
NewComputerName = StrCat('38',ComputerName)
Then use the following to change the computer name locally on the workstation:
IntControl(76,NewcomputerName,0,0,0)
Finally, you must rename the machine account as follows:
PDC = '\\MyPDCComputerName'
OldMachineAcct = StrCat(StrLower(ComputerName),'$')
NewMachineAcct = StrCat(StrLower(NewComputerName),'$')
wntUserRename(PDC,OldMachineAcct,NewMachineAcct,0)
Finally, the workstation must be rebooted for the changes to take effect.

If for some reason the call to wntUserRename() fails, then it would be advisable to use IntControl(76,...) again to restore the workstation back to its original name so as it prevent any domain logon failures that would result from a mismatch between the computer name and the machine account name.

Make an attempt at writing your script and post back relevant snippets of code if you have problems. Test your script thoroughly on a small # of computers before you turn it loose on your entire population of computers in your domain.

Also, do not blindly assume that you can perform this sort of automated rename operation on your domain controllers. There are differences in how PDC's and BDC's have their computer accounts set up and what might work properly for a regular workstation or member server in the domain may not work properly for a domain controller.


Article ID:   W15192
File Created: 2003:03:06:12:05:48
Last Updated: 2003:03:06:12:05:48