Rename a standalone system

User avatar
daniel
Site Admin
Posts: 238
Joined: Tue Jan 09, 2007 9:54 pm
Contact:

Rename a standalone system

Postby daniel » Wed Mar 28, 2007 12:23 pm

The following script allow to rename the system to a new name.
Works on a stand alone system.
Not tested on a domainmember :wink:

'==========================================================================
'
' VBScript Source File
'
' NAME: RenameComputer.vbs
'
' AUTHOR: Paessens Daniel , Hewlett-Packard Company
' DATE : 3/28/2007
'
' COMMENT: This script will change the computername
'
'==========================================================================

Option Explicit

Dim oWshShell 'Windows Script Host Shell object

Set oWshShell = CreateObject("WScript.Shell")

sNewName = "New Name"

'Rename computer
oWshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", sNewName
oWshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", sNewName

'Restart computer
Dim OpSysSet, OpSys
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each OpSys In OpSysSet
OpSys.Reboot()
Next
WScript.Quit


:D

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 1 guest