Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming W2K Pro Computer Via VB Script

Status
Not open for further replies.

lasithg

IS-IT--Management
Jan 14, 2004
18
0
0
LK
Im planning to rename a Windows 2000 Computer which is not attached to a domain. I'm planning to do this remotely via the execution of a Vb Script (So that the renaming is triggered by some event) and restarting the machine.

One option is to search the registry for the Computer Name string and replace it with the new computer name. But I'm sure there must be a shorter method

Ps. NETDOM utility doesnt seem to be very useful here since it's not part of a domain.

Tks in advance
:lg
 
The keys and values in the registry to change are:

"HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"
"HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName"

and

"HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname"

If you have Novell, the you also change "NV Hostname" under Tcpip parameters

This is the full script I use to change those keys:
sNewName = WScript.Arguments.Named.Item("comp")

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 ' oShell

above script is called with a named command line parameter (/comp:<newname>)

I leave it to you to handle the remote part of the problem.
 
Description
Renames a computer and its corresponding Active Directory computer account. Requires Windows XP or Windows Server 2003, and must be run on the local computer.
Rename the computer you on which you run the script &quot;Web Server&quot;

Script Code

strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colComputers = objWMIService.ExecQuery _
(&quot;Select * from Win32_ComputerSystem&quot;)
For Each objComputer in colComputers
err = ObjComputer.Rename(&quot;WebServer&quot;)
Wscript.Echo err
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top