k10n
Jim Klopfenstein's Radio Weblog

 

 

 

 

  Tuesday, August 06, 2002

Controlling IIS6 with managed code


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    


Click here to visit the Radio UserLand website. © Copyright 2003 Jim Klopfenstein.
Last update: 3/14/2003; 11:41:48 AM.

August 2002
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Jul   Sep




Subscribe to "k10n" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.