Windows XP Community - XPHeads



Spyware Doctor

catching wmi error when query fails

microsoft.public.windowsxp.wmi


Reply
  #1 (permalink)  
Old 04-07-2008, 12:45 PM
pantagruel
 
Posts: n/a
catching wmi error when query fails
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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-31-2008, 04:56 AM
Jonathan Liu [MSFT]
 
Posts: n/a
Re: catching wmi error when query fails
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

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--
"pantagruel" <rasmussen.bryan@gmail.com> wrote in message
news:bccfc8b1-85fc-4907-b3bc-0bf5b98f6f43@d2g2000pra.googlegroups.com...
> Hi,
>
> I have the following:
>
> try{
>
> wmiobj = locmachine.ExecQuery("Select * from Win32_NTLogEvent Where
> Logfile = 'Security' And TimeWritten &gt;= '" + dtmStartDate + "' and
> TimeWritten &lt; '" + 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?
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:12 AM.


Registry Mechanic - Free Scan Now
Driver Scanner 2009 - Free Scan Now




Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74