Archive: Any way to detect IIS6 physical web root directory?


Any way to detect IIS6 physical web root directory?
I need to be able to detect and suggest a suitable webroot to install a content management system into. I was previously using "c:\inetpub\wwwroot\" but I was told by my superiors that it should be detected, (even if it would still default to c:\inetpub\webroot), sounds a bit silly in my opinion.

anyway, the web root could be on D: or E: or it could be a multiple webserver configuration running on all 3, I have no idea how to get the 'right' one, and would probably just default to 'c:\inetpub\wwwroot' anyway, hence the pointlessness.

but I have managed to detect if ColdFusion is installed from the registry entries, and quit or continue on that, but due to IIS6 using the 'metabase' and not the registry as such, its a bit harder to access the properties. I have tried a couple of VBS cscripts to try and retrieve the information from the metabase, but it returns different info for each server (obviously), I still think that defaulting to c:\inetpub\wwwroot is more sensible, without any detection code behind, but I've been told its better to try detect the actual working webroot as I might end up causing the user to install the CMS in the wrong directory etc.

thanks for anyone who tried to decipher this and help. hehe!


Try these links I found for scripts that list all folders for all virtual folders.

http://www.iisfaq.com/Default.aspx?tabid=3039
http://www.iisfaq.com/Default.aspx?tabid=2745

If you are only interested in the default web site (first one), then just get the path for W3SVC1.

Alternatively, you could be brave and parse the Metabase directly.
Under IIS 6 it is in XML and stored in "%SYSTEMROOT%\System32\inetsrv\Metabase.xml" and you are looking for something like:

<IIsWebVirtualDir Location ="/LM/W3SVC/1/ROOT"
AccessFlags="AccessRead | AccessScript"
AppFriendlyName="Default Application"
AppIsolated="2"
AppPoolId="DefaultAppPool"
AppRoot="/LM/W3SVC/1/ROOT"
Path="c:\inetpub\wwwroot"
>
</IIsWebVirtualDir>

Duncan (Mr Inches)


Thanks for your reply, I am currently reading how about the XML metabase, but I need to detect IIS5 and IIS6 webroot I believe, as as with IIS5 the metabase is a binary file, I think I'll have to go some other route or just 'dumb provide' the default string "c:\inetpub\wwwroot"

I could just get the default webroot I guess, but its likely to be the wrong one, it would make good for a suggestion as a default though, but thats what I'm using already, it would be the same default even if I put code behind it to detect it!

man, I love trying to explain this to people who dont code.

anyway thanks again, I've got more reading to do at least

:)


hmm it seems one of the example links you gave, I have already been playing with, and the other one is more compact and nearly does what I want, but it borks with a null error if there is no IIS running on that system at all.

I'd love to be able to just default to the inetpub on c: but I know some people might say otherwise, I'd love to see them attempt it though.


thanks for the help, I've convinced my superiors that manual selection of the IIS webroot is the best method though.

:)


I had a similar need for a project I'm working on. I decided to use my program's installation path as an install point for the web pages and then create virtual directories on the default web site using adsutil.vbs provided with the IIS install.

In anyu case, the vbs routines provide a lot of ways to work with and query the web services so you will most likely find useful script in them.