I recently had a need to be able to set the IIS web root from ColdFusion. This is for development on a local machine (where IIS can have only one web root). To do this, I took advantage of the load_iis.bat that my friend Jason Holden created.
I use ColdFusion to write and execute that file in the location that I want to use as the IIS web root.
Here is the function:
<cfargument name="destination" type="string" required="yes">
<cfset var BatchFile = "#arguments.destination#load_iis.bat">
<cfset var LoadIIS = 'cscript %SystemDrive%\inetpub\adminscripts\adsutil.vbs SET /W3SVC/1/ROOT/path "%~dp0"'>
<cffile action="WRITE" file="#BatchFile#" output="#LoadIIS#">
<cfexecute name="#BatchFile#" timeout="999" />
<cffile action="DELETE" file="#BatchFile#">
It is pretty simple. I pass in the folder (including trailing path delimiter) to the function. The "LoadIIS" variable is the code for Jason's load_iis.bat file. That code uses adsutil.vbs that comes pre-installed in the adminscripts folder of inetpub. It calls the "SET" method and passes in an argument for the root of the web site and one that is a shortcut for the current path.
The function writes the .bat file into the root of the site, executes it with cfexecute and then deletes it.
I also could have created the file anywhere and replaced "%~dp0" with "#arguments.destination#" and that should work as well (though I haven't tested it).
With this, it would be pretty easy to write a page that allowed you to switch which site you have as your web root.