Computer rename script does not work on Windows 7

Posted on 2011-10-21
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

    LVL 35

    Author Comment

    I need to use VBScript for that. Besides, that powershell does exactly the same thing
    LVL 51

    Expert Comment

    by:Bill Prew
    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

    LVL 4

    Expert Comment

    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

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    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…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now