Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

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

Avatar of Govvy
Govvy
Flag of United States of America image

Avatar of YZlat

ASKER

I need to use VBScript for that. Besides, that powershell does exactly the same thing
Avatar of Bill Prew
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

~bp
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.

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

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