Epiphany in Advent

Epiphany in Advent

  • Comments 1

I've had something of an epiphany about Windows Management Instrumentation today. I always used to think that WMI was one of those dreary but worthy things that only systems administrators used to be interested in. A big improvement on SNMP for remotely configuring a file server, sure, but of limited interest to developers?

I've just discovered two things that have finally caused my dull head to see the light. Firstly, I came across the TechNet script centre: a fantastic pot pourri of ready-rolled VBScript fragments that enable you to do everything from creating file shares to finding out what software is installed on a particular machine. This resource is a boon to systems administrators, but it also demonstrates what WMI is capable of in the right hands. Unfortunately there's no language filter that provides you with a C# alternative.

But then I made my second discovery - in this case a re-discovery of something I last came across nearly two years ago. On the .NET WMI page, I found an add-in for the Visual Studio Server Explorer that exposes almost every WMI object on a local or remote system as nicely wrapped .NET classes.

Here are a couple of random examples of the kind of thing you can do with these classes:

   computerSystem.JoinDomainOrWorkgroup();
   string manufacturer = computerSystem.Manufacturer;
   int numProcs = computerSystem.NumberOfProcessors;
   int clockSpeed = processor1.MaxClockSpeed();

I'm always being asked how to access some or other hardware or software setting from .NET managed classes. Usually the answer is some really grungy interop into Win32, but now I've got an alternative story.

Am I the only one to have missed out on all this?

  • I appreciated this little snippet you posted. I write a lot of WMI queries but I am unfamiliar with your reference to the computerSystem.xxxxx(). I have never seen that syntax, but I would like to know more about it.
Page 1 of 1 (1 items)