catching wmi error when query fails

P

pantagruel

Hi,

I have the following:

try{

wmiobj = locmachine.ExecQuery("Select * from Win32_NTLogEvent Where
Logfile = 'Security' And TimeWritten >= '" + dtmStartDate + "' and
TimeWritten < '" + dtmEndDate + "'");
}catch(err){
wmiobj=null;
}
WScript.Echo(String(wmiobj));

running as a WSF JavaScript, unfortunately when I run it and the query
doesn't return anything it doesn't raise an error, so wmiobj does not
get set to null

How do I set it to null if the query does not provide a usable return?
 
J

Jonathan Liu [MSFT]

If the query is written correctly it will not fail, it is returning nothing,
basically an empty collection. You can check the Count on "wmiobj", if it
is equal to 0 then you can go ahead an set it to null.

Thanks,
Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top