Wednesday, January 11, 2006

"Using Reflection in C# to print WMI object properties"

Saveen Reddy's blog : Using Reflection in C# to print WMI object properties

"Scenario

You need to dump all the properties in a collection of WMI objects, but you don't want to manually use WriteLine() for each property because it's dull work.

Here is a link to code sample you want to avoid is : this post

What you want

A function that takes collection of WMI objects and prints whatever properties are available.

Using Reflection to get what we want

In a previous post, I wrote about using Mgmtclassgen.exe to generate strongly typed WMI classes. Combine that with System.Reflection and you have an easy way to dump any collection of WMI objects....

..."

This looks like a cool trick to help when working with WMI.

One "problem" with WMI is that there's just SO much information. It really helps seeing the real/live results for a given WMI object. That's were this code snip will help...

2 comments:

Anonymous said...

If you're not limited to C#, the easier route for both WMI and objects in general is to use Monad since it does all the reflection/display logic for you for arbitrary objects.

Greg said...

Nice...

I'm waiting for Monad to RTM before I play with it but in reading I've done, it sure looks cool.