Computer rename script does not work on Windows 7

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 		
        		HandleError(ErrCode)
    		End If
	Next

Open in new window

LVL 35
YZlatAsked:
Who is Participating?
 
RobSampsonCommented:
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.

Rob.
0
 
GovvyCommented:
0
 
YZlatAuthor Commented:
I need to use VBScript for that. Besides, that powershell does exactly the same thing
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Bill PrewCommented:
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

~bp
0
 
CharlWiehahnCommented:
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.

0
 
YZlatAuthor Commented:
That was not exactly it, but it was an issue not related to my script. Thank you for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.