Mark Gilbert's Blog

Science and technology, served light and fluffy.

New Tool Published: IIS Tweak

Standard operating procedure for me and my colleagues when working on a web site locally is to take over the default web site – http://localhost.  However, we all work on multiple projects.  Switching from one to another involves opening up the IIS management console, drilling down to “Default Web Site”, opening up the properties, clicking on the Home Directory tab, browsing out to the new folder, and then clicking OK a few times to save the new settings.  I must have done this routine half a dozen times last week alone, not to mention how many times my teammates and I have done it in the past months.

Luckily, the tediousness of this process finally annoyed me to the point where I wrote a new utility to speed it up – IIS Tweak.

IISTweak

The first version, 0.1.0, uses the same treeview navigation controls that another of my utilities, NAntRunner, does.  Each node on the list has a path to a web site’s root directory tied to it.  When I double click an entry in the list, the utility will modify the IIS Metabase for web site with ID “1”, the default web site, and change the “Path” property to that path.  This magic is the result of these four lines:

Dim MyLocalhost As DirectoryEntry

MyLocalhost = New DirectoryEntry(“IIS://localhost/w3svc/” & Me._WebSiteID & “/ROOT”)
MyLocalhost.Properties(“Path”).Item(0) = value
MyLocalhost.CommitChanges()

“Me._WebSiteID” in this case happens to be a private variable initialized to “1” in the form’s constructor.  If you know the ID for another virtual directory on the server, you could substitute it here and modify that site’s Home Directory, or any of a number of other properties.  I’ve only done a little with the IIS Metabase, and the System.DirectoryServices namespace, but it looks like most of IIS (if not all) can be programmatically controlled; this is merely one simple example.

Full source code can be found on CodePlex: http://www.codeplex.com/IISTweak.  Enjoy!

Advertisements

September 28, 2008 - Posted by | Tools and Toys

Sorry, the comment form is closed at this time.

%d bloggers like this: