Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#328184 - 18/12/2009 22:02 Rubbing the BBS lamp: Access WMI information on Server 2003?
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Possibly among the most obscure things this BBS has ever been asked. But other really strange stuff has gotten answers on this BBS, so I'm trying.

If you want to write a script to monitor performance variables on your Windows computer, you do it by querying WMI. There are two ways of doing this. One is to directly write a single query to the WMI object. You can retry that query multiple times with different parameters if you want, to get other types of data. The other way is to set up what's called a "refresher" object, and then query the values within it. Then when you want new information, instead of instantiating a new object for the new query, you just call objRefresher.Refresh and look at the values again.

Everything I've read on the 'net says that I should be able to use either method, and that both methods should work fine on both Vista and on Server 2003.

Both methods work great for me on Vista, but on half a dozen Server2003 boxes I've tried it on, I get strange results with the "Refresh" version of the query. The strange results are: The query works, and returns data, but all of the data fields are NULL except for the "Name" field (which is always right).

Here is my stripped-down sample code. Save this code as a ".VBS" file on your hard disk and double click on it:

Code:
moved to an attachment


Anyone know what's up with this?


Attachments
tonyscode.vbs (130 downloads)



Edited by wfaulk (19/12/2009 01:20)
Edit Reason: moved code to attachment
_________________________
Tony Fabris

Top
#328186 - 19/12/2009 00:01 Re: Rubbing the BBS lamp: Access WMI information on Server 2003? [Re: tfabris]
gbeer
carpal tunnel

Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
How about converting that code to an attachment? Please Please.
_________________________
Glenn

Top
#328187 - 19/12/2009 01:18 Re: Rubbing the BBS lamp: Access WMI information on Server 2003? [Re: tfabris]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
From here:

Quote:
[H]ere’s the problem. You begin by using ExecQuery to return performance counter data for all the processes and their properties. So far so good, with one minor caveat: for some reason, more often than not the first time you query a performance monitoring class you’ll get back either 0 or Null for all the property values. Why? To be honest, we don’t know; that’s just the way it works.


So maybe try refreshing it twice before printing it out.
_________________________
Bitt Faulk

Top
#328208 - 21/12/2009 15:17 Re: Rubbing the BBS lamp: Access WMI information on Server 2003? [Re: wfaulk]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Yup, that was the solution. The HeyScriptingGuy forums had the same answer for me. Thanks!
_________________________
Tony Fabris

Top
#328320 - 28/12/2009 21:12 Re: Rubbing the BBS lamp: Access WMI information on Server 2003? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Okay, Bitt. You were awesome enough to find that last answer, how about this follow up?

Here's the quote from the HeyScriptingGuy forum I just made. Let's see if you can beat them to the punch... smile

I'm using an HTA (VBScript contained within an HTML Application page) to query WMI at regular intervals for the memory usage of a few key applications.

There are two ways I can do this:
1. Directly querying WMI each time through the loop, creating and destroying a query object each time.
2. Setting up a single Refresher object, which is refreshed each time though the loop, and then getting the values of its members each time though the loop.

The direct query method works great and never fails, but I fear that the constant creation and destruction of the query object might be eating memory.

If I use the "refresher" method, it works fine at first, but then after several minutes, it starts failing: Suddenly it starts returning zeros or nulls for many of its values. Once it does this, the return values are always zero for those processes for a long time. The time period that it takes to start failing can be anywhere from several minutes to half an hour. And here's the kicker: it only fails on Server 2003. On Vista or Windows 7, it works fine without failing.

I have also notice that the two methods, when they're working, return significantly different values despite the fact that I'm querying the exact same values both ways.

Questions:
- Why does the refresher method suddenly fail unexpectedly? (And why only on Server 2003?)
- Why do the two different methods return different values?
- Why does my Direct query method seem to eat memory, despite the fact that I'm setting the object to "Nothing" when I'm done with it? Can anyone help me prevent the direct method from eating memory? I'd give up on the refresher method and just query directly if it weren't for this.

Attached is my example code in VBScript. It must be saved as a .HTA file in order to work. Run it on Server 2003 to see the results (you may have to wait a while).


Attachments
WMITest5.hta (129 downloads)

_________________________
Tony Fabris

Top