I have the following simple script:
--- begin -----
Set wmi=GetObject("winmgmts:{impersonationLevel=impersonate}!root/wmi")
Set ws=wmi.ExecQuery("select * from MSNdis_80211_BSSIList")
On Error Resume Next
For each wa in ws
WScript.Echo "Adapter name=", wa.InstanceName
Next
Wscript.Echo "after query:" & Err.Number
---- end ---------
This works fine if there is at least one wireless adapter.
If there are NO wireless adapters and I omit "On Error Resume Next",
an error occurs: my.vbs(6, 1) (null): 0x8004100C
The error is on the line of "For each wa in ws".
With "On Error Resume Next", the script runs to the end
and Err.Number is 424 (Object required).
I don't understand what this error means and why it occurs.
If the query returns an empty set, the For loop should not execute at all,
correct?
When there are one or more wireless adapters, the loop works fine, no error.
So, instead of empty set, the query returned something bad to ws?
I'd like to distinguish the empty set from error. I tried to
test IsEmpty(ws) or IsNull(ws) before the For loop -
both tests return false (that's, not empty and not null)
Is this a WMI or vbscript problem, or a hole in my head?