Count in execquery for wql query

1.6k Views Asked by At

I am trying to connect to lenel and using WQL to fetch result. WQL when runned in WMI explorer returns record.

Set objServices = GetObject("winmgmts://./root/onguard")
Set cardSet = objServices.ExecQuery("select * from Lnl_Badge where id =11111")
if not cardSet is nothing then
Response.Write("<br/>cardset has something")
vContinue = true
else
Response.Write("<br/>cardSet set is nothing")
Exit Function
end if

Response.Write("<br/>count ")
Count = cardSet.Count
Response.Write(Count)

The problem is that the value of Count is coming nothing and program exit from the current function. Any idea what is wrong.

"Cardset has something" is displayed though.

Edit:

For checking the syntax i did the following for cim2v

Set objWMIService = GetObject("winmgmts:")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
Response.Write(colItems.Count)
for each colItem in colItems

If Not colItem Is Nothing Then
    Response.Write("<br/>")
Response.Write(colItem.ProcessID)
end if
next

To my suprise its working....then why the above code is not woking... :(

Edit: error in the log file

(Tue Aug 20 11:50:22 2013.179589208) : WDM call returned error: 4200
(Tue Aug 20 11:50:22 2013.179589208) : WDM specific return code: 4200
(Tue Aug 20 11:50:22 2013.179589208) : 
1

There are 1 best solutions below

0
On

From my understanding of the WMI API reference, the SWbemServices.ExecQuery method will always return an SWbemObjectSet object if you didn't encounter an error, regardless of whether or not there are any results in that object.

If your query returns 0 results you'll still have a valid object in cardSet, so the If Not cardSet Is Nothing statement will always trigger, unless there was an error, but at the same time count will still return 0.