Solved

Modify script to prompt user for string

Posted on 2011-09-29
4
295 Views
Last Modified: 2012-06-21
I want to modify the below script so that instead of reading the serial tag to rename a computer, it will prompt me for what I want to use as the computer name the run the rest of the script to change the computer name.
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2¿)

‘Part 1 – Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery (“Select * from Win32_SystemEnclosure”)
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> “” Then exit For
Next

‘Part 2 – Assign computer name to serial/service tag number
Name = strSN

Set colComputers = objWMIService.ExecQuery (“Select * from Win32_ComputerSystem”)

For Each objComputer in colComputers
err = objComputer.Rename(name)

if err <> 0 then
wscript.echo “There was an error renaming the machine. Please restart, and try again.”
else
wscript.echo “Machine successfully renamed: ” & Name
end if

Next

Open in new window

0
Comment
Question by:lemonville
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36818469
Hi, just change this
‘Part 1 – Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery (“Select * from Win32_SystemEnclosure”)
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> “” Then exit For
Next

‘Part 2 – Assign computer name to serial/service tag number
Name = strSN

Open in new window


to this:
strSN = InputBox("Enter new computer name:")

Open in new window


Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36818474
Oops, sorry.  Change that first block to this:
name = InputBox("Enter new computer name:")

Open in new window

0
 
LVL 1

Author Comment

by:lemonville
ID: 36818479
And remove part 1?

Thanks!
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36818587
Yes, replace the part 1 block that I put in the snippet, with just that one line.

Rob.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question