Programmatically adding PHP script engine to IIS 5.1 metabase ScriptMaps

I spent a few days on investigating how to modify IIS metabase from script. What I need is to add PHP engine to IIS programmatically during installing PHP. Now it is done and here is a few notes on this.

First, IIS metabase can be accessed using the following code:
var svc = GetObject("IIS://localhost/W3SVC");

The metabase object can be enumerated and each item of the enumeration can be enumerated to. The elements of this hierarchy represent folders you can see in IIS management console.

Each element contains ScriptMaps item, which contains script mapping items for the particular IIS application.

What the following function does is going through all IIS applications and applying the callback for each of them:

function walk(obj, callback)
{
	callback[0][callback[1]](obj);
	var e = new Enumerator(obj); 
	for(; ! e.atEnd(); e.moveNext()) {
		var item = e.item();
		if ((item.Class == "IIsWebFile") || (item.Class == "IIsWebVirtualDir")
			|| (item.Class == "IIsWebDirectory") || (item.Class == "IIsWebServer"))
		{
			walk(item, callback);
		}
	}
};

As you see, each item of enumeration has the class property that is used for detecting whether it should be processed or not.

Adding PHP engines means that each ScriptMap element of the processed items should have the following entry:
.php,c:\path\to\php\php5isapi.dll,5,GET,HEAD,POST

and the following code adds it:

function addPhpIsapi(obj)
{
	var scriptMaps = obj.GetPropertyAttribObj("ScriptMaps");
	if ((scriptMaps != undefined) && (scriptMaps.IsInherit == false)) {
		var resultArray = obj.scriptMaps.toArray();
		resultArray.push(".php," + this._pkgFolder + "\\php5isapi.dll,5,GET,HEAD,POST");
		// This hint we need to convert JS Array to array of variants
		var dMaps = new ActiveXObject("Scripting.Dictionary");
		for (var key in resultArray) {
			dMaps.add(resultArray[key], '1');
		}
		obj.ScriptMaps = dMaps.Keys();
		obj.SetInfo();
	}
};

This code now is the part of Jamp installer. But because this functionality is dangerous, this code is not run during default installer and it recommended to backup the metabase before running it.