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!

How to Obtain current computer name from Registry

Status
Not open for further replies.

simdan42

Programmer
Jul 17, 2002
118
0
0
US
I need to get the current computer name from the registry. Then store that value. Delete the first few characters from
the value and add more charater to the value and then set the new value as the computer name.(ie Current
Computer name = 1234Smith. I need to remove the 1234 and replace it with ABCD)
 
Open regedit and search for 1234Smith. Edit it.
In XP right click My computer, select properties, Computer name tab.

Cheers,
Jim
iamcan.gif
 
I am sorry, I should have specified that I wish to do this via a script. I have many machines to change the name to a new naming convention.
 
Assuming you're after VB code, try:

Code:
Dim strCompName

Set objWshShell = WScript.CreateObject("WScript.Shell")

strCompName = objWshShell.RegRead("HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName")
objWshShell.RegWrite "HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName", Right(strCompName,Len(strCompName)-2)
 
Oops! The RegWrite line should include another \ComputerName after the last ComputerName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top