Tuesday, 14 October 2008

WMI Code Generator

Whilst writing some unit tests to exercise a set of BizTalk orchestrations, I found I needed to "stop" and "unenlist" one of the orchestrations being tested (and of course re-start after the test had finished).

The obvious choice would be WMI and MS ship some great samples in the SDK, however they're all in VBS.

I didn't want to "call" VBS files, I really wanted to wrap the WMI in a function to call from my unit test, but my unit tests are written in C#.

I did some Googling to find a quick translation for VB GetObject() to C#... There's no direct C# translation but looking at some of the posts I'm not the only one who asks this question...

However I felt that a lot of the posts missed the point, poeple were trying to use the Marshall namespace/class to reproduce GetObject() behaviour ..

Marshal.GetActiveObject() and Marshal.BindToMoniker()

Anyhow, to cut a long story short I stumbled upon a very, very nice utility from MS WMICodeGenerator (must be the last person in a long line to have done so), that generates WMI code for you in the language of your choice...

Actually it's better than that, it finds all the WMI assemblies, and when you select a namespace/class and method it'll find the relevant assemblies you have to act upon and then output the complete code snippet for you to use... Brilliant!

No comments: