Computer rename script does not work on Windows 7

Posted on 2011-10-21
Medium Priority
Last Modified: 2012-06-27
The VBScript below works fine on Windows XP but doe snot on Windows 7. It runs without an error but does not rename. Username login provided is an elevated account

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

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

	For Each objComputer in colComputers
        	ErrCode = objComputer.Rename(new_name, strPassword, strUser)
    		If ErrCode <> 0 Then 		
    		End If

Open in new window

Question by:YZlat
LVL 13

Expert Comment

ID: 37008395
LVL 35

Author Comment

ID: 37008439
I need to use VBScript for that. Besides, that powershell does exactly the same thing
LVL 59

Expert Comment

by:Bill Prew
ID: 37008610
It looks like you are trapping for errors, could I see the rest of the script, including the error handler?

Also, have you tried removing the following line to see if any errors are reported.

On Error Resume Next

Open in new window

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 37010917
Hi YZlat,

I just tested your code on my Windows 7 64bit pc and it ran fine. I dont think that there is a problem with your script, rather I think the change is being stopped by User Account Control.

I would suggest you turning User Account Control off via the "Change User Account Control settings" under the "User Accounts" option in the control panel by moving the slider to "Never notify" and then re-test your script on the pc.

LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 37013690
Instead of turning off UAC, you can run cmd.exe by right-clicking it, and selecting Run As Administrator, then type:
cscript RenamePC.vbs

It should work.

Alternatively, if you make a batch file with that same command in it, you can right click the .bat file and select Run As Administrator.

LVL 35

Author Closing Comment

ID: 37039845
That was not exactly it, but it was an issue not related to my script. Thank you for your help

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

839 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