WMI the .NET way


I’ve just finished some work on a service I’m developing, and one of the features I’ve added was to publish state information via WMI, viewable from an ASP page. I’m impressed!!! just a handful of lines of code and bang! there yer go, job done.

I kept my state in a public class, with private attributes, accessible via an interface with public read-only properties, and those properties I didn’t want exposed via WMI, I marked “ignore”, the only constraint being that your properties must be serializeable, added this attribute to the class: –

[InstrumentationClass(InstrumentationType.Instance), ManagedName(“InstanceClassName”)]

Added this to the assembly info: –

[assembly: Instrumented(“root/mynamespace”)]

Added an installer (which registers the WMI schema), you can use the DefaultManagementProjectInstaller or add a System.Management.Instrumentation.ManagementInstaller to your other installers, and run installutil. Fire up your app and away you go.

Sadly it’s not all good, as in .NET 1.1 you can’t support writeable properties in your instance classes (you can expose them but WMI clients can’t set them), nor support methods, I haven’t looked yet but perhaps that will come in .NET 2

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.