Tool to generate AhAdmin code for actions in IIS7 UI

If you ever write AhAdmin code, this is for you.I have written a tool which generates equivalent JavaScript/C#/VB.Net AhAdmin code for actions done in IIS7 UI.

IIS7 configuration system gives access to IIS config files via a set of COM APIs. You can read/write to IIS configuration using these APIs in a script or C/C++ or using any of the managed language. All the tools which are shipped with IIS like managed APIs (Microsoft.Web.Administration), UI (IIS Manager), WMI provider uses these COM APIs internally to perform all the configuration operations. When you do an action in the UI, UI is making calls to these COM APIs (actually via MWA). Programming against COM APIs provided by IIS configuration system requires extensive understanding of these APIs and also IIS schema. Also you are required to know what exactly you want to change in the configuration. So when if you want to enable IIS detailed error messages programmatically, you are required to know which property should be changed to what value to have the desired effect. IIS Manager does present the properties in more readable form which makes it easier to decide what changes you want to make to the system which is helpful to the administrators but not developers. Imagine if you could just do an operation using IIS Manager and get the equivalent AhAdmin code which you can copy-paste in your application. This is exactly what AhAdminCodeGenerator is written to do. In the snapshot below, you are looking at JavaScript code generated when I created a site using IIS Manager.

 

AhAdminWriter 

How does it work?

This tool uses detours to capture calls made to underlying IIS configuration system AhAdmin COM APIs. When you use this tool to launch IIS Manager, it launches inetmgr.exe and injects code in the process which captures all the calls to AhAdmin APIs. When UI tries to read/write configuration using AhAdmin APIs, injected code builds the API call data as XML element and transfers this data to AhAdminCodeGenerator application before calling the original API code. On receiving this data from the detoured APIs, AhAdminCodeGenerator inspects the method call and rejects it if it is not desirable as per capture options configured. If the call is desirable, this tool looks at code generation options and puts the code generation process on hold if tool is configured to generate code for write calls only. On call to CommitChanges, tool dumps out all the write calls and also dependent calls which were needed to create the object on which SET was called. Result of this process is pretty much what you in need in most cases.

Features

1. Supports both Vista RTM and Vista Sp1 (and Win2K8) version of AhAdmin interface.
2. Generates JavaScript, C# and VB.Net code for UI actions.
3. Standard features like find text, goto line, copying/saving code etc are included.

Installation and how to use steps

To install this tool, download attached file AhAdminCodeGeneratorInstall.zip, unzip and run the installer (AhAdminCodeGeneratorInstall.EXE).
To use the tool, do the following.
1. Run AhAdminCodeGenerator.exe as elevated.
2. If you are using this tool on vista RTM system, click IIS Manager->Use Vista RTM version.
3. Click IIS Manager->Start or press F5.
4. Do actions in UI and see the equivalent code in the AhAdmin code generator. Use the code as you see fit.

Note: AhAdmin code generator will not work on x64 systems as this tool uses detours express edition and not professional edition which supports x64.
Note: Because of the way this tool works, you cannot use it when IIS Manager is connected to a remote box.
Note: Default settings will make this tool emit code for write calls only. You can change call capture options and code generation options to control what code is generated.

Capture and code generation Options

You can use capture options window to configure what API calls you are interested in. Defaults are set based on what APIs are mostly used when UI is reading/writing configuration. In most cases, you won't need to change this. Code generation options defaults are set to generate code for write calls only. Also by default, code for all GetMetadata and SetMetadata calls won't be generated. These defaults helps to remove code of all read calls which UI is making to display data. If you are really interested in seeing code for read calls as well, you can change code generation options accordingly. Warning: IIS Manager is not super efficient in reading configuration. You will see lot of unwanted code if you turn on code for read configuration calls.

CaptureOptions  CodeGenOptions

Generating code


To generate code, you have to launch IIS Manager using this tool so that it can inject API hooks before starting inetmgr.exe. If you are using this tool on Vista RTM, please select "IIS Manager->Use Vista RTM version". To launch IIS manager, click IIS Manager->Start of hit F5. Make changes using UI and see the code getting generated in AhAdmin Code Generator panes. If "Start" is shown disabled, you probably closed IIS Manager directly and not using "IIS Manager->Stop". Just click "Stop" which will enable "Start" menu item.

InetMgrStart 

Snapshot below has JavaScript code which got generated when I created an application pool with managed runtime version as 1.1.

CreateAppPoolJavaScript 

C# code which got generated when I created a web site is shown below. Notice code generated at the bottom to start the web site. This part of the code will only get generated if you run the tool on Vista Sp1 or Win2K8. Vista RTM didn't have dynamic properties functionality which is getting used by the UI in Vista Sp1 and Win2K8 to start the site.

CreateSiteCSharp 

As a final example, following VB.Net code gets generated if you disable anonymous authentication and enable basic authentication for a site. 

SiteAuthenticationVBNet 

Hope this tool will make life of AhAdmin code writers much easier. This can easily be extended to generate code in C/C++ and possibly MWA code and appcmd commands. If there is sufficient interest for these features, I might decide to add. Let me know if you would like these features or would like the source code to add this functionality yourself.

-Kanwal-

2 Comments

Comments have been disabled for this content.