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

Rename Computer

Status
Not open for further replies.

nicknel9

Technical User
Dec 7, 2007
5
US
How do I take this script and have it ask what name to rename it to.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
err = objComputer.Rename("WebServer")
Next
 
If you want a popup to ask, use inputbox.

If you want to ask from the cmd line (only works with cscript: not with wscript), use WScript.StdIn.Readline to get the input from the user, WScript.StdOut.WriteLine or WScript.Echo to prompt the user.
 
Thank you,

I guess being new the game. Where would I want to put the inputbox command?
 
Code:
newname = inputbox ("New name")
For Each objComputer in colComputers
    err = objComputer.Rename(newname)
Next
 
A safer way:
Code:
newname = InputBox("New name")
If Trim(newname & "") <> "" Then
  For Each objComputer in colComputers
    err = objComputer.Rename(newname)
  Next
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top