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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a computer name using VB script

Status
Not open for further replies.

Aslamvs

Technical User
Joined
Jul 8, 2002
Messages
472
Dear All,

Can we change a computer using a vbscript in such a awy that the script should prompt for new computer name.

Means after runnig the script it should prompt for new computer name which has be given to the PC.

I m using XP workstation.

Thanks in advance
Aslam


Aslam
 
When you join a domain, the computer name is registered in active directory. I know you can change the computer name in the local registry (several places must be changed), but what about active directory? If you are part of a domain, you should consider this entry on the server as well.
 
Seaspray0

The computer is not a member of doamain.

Aslam
 
Hi All,

I managed to find out the script
this is the script i use
=========================================================

Name = InputBox("Enter the new name of the computer you wish to Change")

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

' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")

Return = objComputer.rename(Name)
If Return <> 0 Then
WScript.Echo &quot;Rename failed. Error = &quot; & Err.Number
Else
WScript.Echo &quot;Rename succeeded. Reboot for new name to go into effect&quot;
End If

Next
============================================================

Aslam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top