Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI query....capture empty collections?

Status
Not open for further replies.

VulcanJedi

Technical User
Oct 2, 2002
430
US
I have the following lines of code:
the issue is when colleggedEvents is empty and in nothing is returned from the query than the for each loop crashes; is there a way to capture if the query is empty??


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

Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '1106' and Type = 'error'")

For Each objevent In colLoggedEvents


[yinyang] Tranpkp [pc2]
 



Hi,

How 'bout this...
Code:
Set colLoggedEvents = objWMIService.ExecQuery _
        ("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
            & "EventCode = '1106' and Type = 'error'")
if not colLoggedEvents is nothing then
  For Each objevent In colLoggedEvents
    'do stuff

  next
end if


Skip,

[glasses] [red][/red]
[tongue]
 
no worky; sorry fyi is vbscript...mabye wrong forum

[yinyang] Tranpkp [pc2]
 
And what about this ?
If IsArray(colLoggedEvents) Then
For Each objevent In colLoggedEvents
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry skip; simply mistake on my favorites bar.
PHV...not dice brother.

[yinyang] Tranpkp [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top