views:

205

answers:

2

When querying for large ammount of data through WMI (say the windows events log Win32_NTLogEvent) it is very useful to know what kind of numbers you are getting yourself into before downloading all the content. Is there a way two do this?

From what i know there is no "Select Count(*) FROM Win32_NTLogEvent" in WQL.

From what i know the Count property of the ManagementObjectCollection actually enumerates through all the results whether you have the Rewindable property set to true or false.

If it cannot be done in .NET, can it be done by directly using the underlying IWbem objects Thanks

+2  A: 

The underlying IWbem objects also return an enumeration.
E.g. The IWbemServices::ExecQuery Method returns an IEnumWbemClassObject

However, see Improving Enumeration Performance for a couple of ideas.
Notably, the WBEM_FLAG_FORWARD_ONLY.
If you're in C# I'm guessing it would be calling ManagementObjectSearcher with EnumerationOptions.Rewindable set to false. Rewindable is true by default, so turning it off should give some improvement.

(You could also profile to see if there's any performance improvement if you just ask for one (key) property in your query. E.g. Select RecordNumber FROM Win32_NTLogEvent instead of Select * FROM Win32_NTLogEvent.
In theory not as much info would need to be instantiated, though in realityit still has to enumerate everything, and I don't remember if I ever saw any improvement from that. Worth a timing check, though.)

Daryn
A: 

It appears that it cannot be done. The next best thing is the answer provided above by Daryn.

Mark