Script error

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Script error

Post by ErikJan »

I have two identical PCs (well, the hardware is the same -Win7- and the software is supposed to be the same too). I roughly checked the installed software and Windows updates and these look 100% identical too.

I run BGINFO (to put some text on the Desktop) and in there I provide system up-time via a script. The script starts like this:

Code: Select all

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * From Win32_PerfFormattedData_PerfOS_System")

For Each objOS in colOperatingSystems
		intSystemUptime=objOS.SystemUpTime
On one system (and many more before) this works, no problems. On the other system I get an error saying "Error evaluating scripted field UpTime", with a pointer to the last line in the code fragment above.
If I take the script and rename it to give it a VSB extension, I get an error 0x80041017 when I run the script...

Why does this work in all systems but not in this one which is (should be) identical? Ideas? How can I troubleshoot this?

PJ_in_FL
5StarLounger
Posts: 1090
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Script error

Post by PJ_in_FL »

ErikJan wrote:...On one system (and many more before) this works, no problems. On the other system I get an error saying "Error evaluating scripted field UpTime", with a pointer to the last line in the code fragment above.
If I take the script and rename it to give it a VSB extension, I get an error 0x80041017 when I run the script...

Why does this work in all systems but not in this one which is (should be) identical? Ideas? How can I troubleshoot this?
Here's the abbreviated output from the old Technet Script Center help file:

Code: Select all

strComputer = "."

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

set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colItems = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfOS_System").objectSet

objRefresher.Refresh

For Each objItem in colItems
    Wscript.Echo "System UpTime: " & objItem.SystemUpTime
    objRefresher.Refresh
Next
Note the use of "impersonationLevel" in the WMIService object definition. I don't know the details, but I have no problems running this code on my work Win 7 Pro laptop...

YMMV
PJ in (usually sunny) FL

PJ_in_FL
5StarLounger
Posts: 1090
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Script error

Post by PJ_in_FL »

Well, a little Googling found the "{impersonationLevel=impersonate}!" portion of the WMI object call defines the security level. Error 0x80041017 is "invalid query" which could come from a security setting issue.

HTH
PJ in (usually sunny) FL

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Script error

Post by ErikJan »

Where the updated script (with the impersonate clause) works on the same systems where the original script also works, regretfully the opposite is also true: on the system where I had my problems, this updated script (also in 'vbs' version) generates a new error in this line:

Set colOperatingSystems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_System").objectSet

"Invalid class"; 80041010

I'm OK to check security settings if that could be at the basis here (even if the two current test systems are supposed to be the same); but where -and how- do I start?

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Script error

Post by ErikJan »

Anyone with an additional clue for me here maybe?

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Script error

Post by Rudi »

Sorry. :sorry: Not from me...way out of my depth.
Hope you get a flash of genius soon!
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

PJ_in_FL
5StarLounger
Posts: 1090
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Script error

Post by PJ_in_FL »

Possibly need to add a WMI component called out in this blog: WMIC PRODUCT Returns Invalid Class Error 0x80041010.

"...install an optional Windows component called "WMI Windows Installer Provider". This component can be installed through "Add/Remove Windows Components"... look for the "Management and Monitoring Tools" group."
PJ in (usually sunny) FL

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Script error

Post by ErikJan »

That's a solution for XP systems it seems (I did some searching); it does not apply to Win7

PJ_in_FL
5StarLounger
Posts: 1090
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Script error

Post by PJ_in_FL »

ErikJan wrote:That's a solution for XP systems it seems (I did some searching); it does not apply to Win7
Right. Sorry.

Does the error throw an event on the failing PC? If so can you post the event details?
PJ in (usually sunny) FL

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Script error

Post by ErikJan »

Just checked... no