Real Geek Forums  

Go Back   Real Geek Forums > Archives > Operating Systems > Windows XP > Windows XP WMI

Notices

Reply

catching wmi error when query fails

 

LinkBack Thread Tools Display Modes
Old 04-07-2008, 12:45 PM   #1 (permalink)
Default 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?

pantagruel
Guest
 
Posts: n/a
Reply With Quote  
Old 05-31-2008, 04:56 AM   #2 (permalink)
Default 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...
Quote:
> 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?
>
Jonathan Liu [MSFT]
Guest
 
Posts: n/a
Reply With Quote  
Reply

Tags
None

Thread Tools
Display Modes

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

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
VPN connection was working, now fails with error 651 jahyen Windows Vista Networking & Sharing 2 02-26-2007 11:55 AM
WMI query local computer fails with access denied despite being local admin xr7 Windows XP WMI 0 11-17-2005 06:48 PM
Catching all internet activity on my network Mike Riston Windows XP Network & Web 7 07-25-2003 03:59 PM
Catching all network activity. Mike Riston Windows XP Hardware 0 07-23-2003 04:39 AM
Connection Error - Unable to query version information Xdrive, Inc. Support Windows XP New Users 0 07-15-2003 08:33 PM


All times are GMT. The time now is 11:04 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright © 2005 - 2007 RealGeek.com. All rights reserved.

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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90