Reputation: 5894
I have a very simple WMI test-script that I am running locally on a server to diagnose a problem I'm having getting WMI some data.
Essentially, all WMI queries I run on this machine (locally) fail with an error code 0x80041017
.
Option Explicit
Dim WmiQuery
WmiQuery = "SELECT * FROM Win32_Processor"
Dim objSWbemLocator
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Dim objWMIService
Set objWMIService = objSWbemLocator.ConnectServer("localhost", "root\cimv2")
Dim results
Set results = objWMIService.ExecQuery (WmiQuery)
Dim row
For Each row in results
Next
I'm not even trying to view any properties yet, but it fails on line 16, which is the For Each row in results
line.
Here's the output of running it in a console:
c:\test>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
c:\test\test.vbs(16, 1) (null): 0x80041017
Running that query through wbemtest gives the description "Invalid query", even though the same query runs on other servers. Is something not registered in WMI or something?
Upvotes: 1
Views: 14681
Reputation: 1418
I think it may be to do with how you're getting your WMI object.
How about this:
Option Explicit
Dim wmi,col,itm
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set col = wmi.ExecQuery("Select * from Win32_Processor")
For Each itm in col
WScript.Echo itm.Name
Next
Set wmi = Nothing
Set col = Nothing
WScript.Quit
Seems to work for me... Don't think you need all the WBemLocator guff...
Upvotes: 0