For the last couple of days, I’ve been working with the System.Management classes. After a couple of false steps, I was able to create a web service interface to a management task on IIS 6, and it wasn’t nearly as hard as it first appeared.
What I needed to do was to create a web service to start and stop individual IIS 6 web sites. The way to do this is through WMI (Windows Management Instrumentation), which was unknown territory to me.
Windows .NET Server RC1 comes with a VBScript file called iisweb.vbs (1204 lines) that can be used to perform a number of IIS management tasks. It makes use of two Windows script components, IisScHlp.wsc (1189 lines) and cmdlib.wsc (1059 lines). All in all, that's a lot of VBScript to wade through. (All the files are in \Windows\System32).
At first I thought I’d use .NET COM interop to use the script components, but luckily for me, tlbimp didn’t like their typelibs. So I searched around in the .NET framework and found the System.Management classes. Here’s something like the code I wound up with.
Each method takes the friendly name of the server (in WMI-speak, the ServerComment). To manage the default web site, pass the string “Default Web Site” as the parameter.
I used the [SoapRpcMethod] attribute so I could interact with this service using the SOAP moniker in Windows XP. With it, I can start my web site with these two lines of VBScript:
set obj = GetObject("soap:wsdl=http://myserver/myservice.asmx?wsdl")
obj.start
Pretty neat, huh? [Later... Gordon accuses me of "reading the SDK docs," something I don't do nearly enough. I found what I needed for this project by bouncing around from page to page in the MSDN Library a good bit and trying things.]
4:14:32 PM
|