Wednesday, April 25, 2018

Does ManagementClass load all of the properties?

Leave a Comment

When using ManagementObjectSearcher - one can search for specific properties (instead of all by *).

What happens when instantiating a ManagementClass (i.e. new ManagementClass(someClass)), does it load all of the properties, or is it only some sort of pointer, and will not load the properties?

.

(I'd also be happy to know what happens when using ManagementObjectSearcher with a *, does it load anything besides the properties, or is it just like specifying all of them explicitly? Logically, it should simply mean "all", but from here it seems otherwise.)

1 Answers

Answers 1

Nothing happens when you instantiate it. It just stores the query, scope and whatever else you may have specified. Same goes for ManagementObjectSearcher

When you call .Get(), the query is executed against the current scope. As for ManagementObjectSearcher, the actual behavior depends on whether it's a class enumeration or instance enumeration (e.g. a query)

A query is executed and directly returns results (any properties) whereas a class enumeration will bind to the underlying WMI object without actually loading anything until you call .Get() somewhere.

does it load all of the properties, or is it only some sort of pointer

It's a pointer to the CIM Object Manager. The underlying objects are only loaded when initialize is called with true (indicating that you want to bind to the underlying WMI object). This is what the queries are executed against.

Looking at the various calls to Initialize(), it seems at first glance that the objects are only bound when you're requesting properties or qualifiers. Invoking methods will not bind them.

I'd also be happy to know what happens when using ManagementObjectSearcher with a *

Nothing until you execute the query. Which, by default, performs a shallow enumeration on the object. This might return the qualifiers in addition to the properties, but I'm not entirely sure on that.

Also interesting (including the sibling articles): https://technet.microsoft.com/en-us/library/cc180561.aspx

I hope this helped at all :)

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment