Question

How do I get the Root/Home Directory of a website in IIS6 using a batch file??

My Scenario:

I am creating a tool to summarise and report of sites in IIS. I am using batch files and running iisweb /query to get all the sites then looping over the results and using iisvdir /query "Website Name" to get the virtual directories.

However it has to be backwards compatible with IIS6 and I am having trouble getting the Home Directory of the site.

Was it helpful?

Solution

I don't think you can do this directly from a batch file, but you should be able to do it from a vbscript which you can call from a batch file.

The trick is to use the IIS WMI provider which gives you access to the IIS metabase. For example, the script below should echo the name and path of every virtual directory on the local server.

set provider = GetObject("winmgmts://localhost/root/MicrosoftIISv2") 
set results = provider.ExecQuery("SELECT Name,Path from IISWebVirtualDirSetting")
for each item in results
  WScript.Echo item.Name
  WScript.Echo item.Path
next

If you saved this script as iispaths.vbs (just as an example), you could then call it from a batch file with:

cscript //nologo iispaths.vbs

Unfortunately I don't have access to a machine with IIS6, so I am unable to test this at the moment, but if you have any problems getting it to work, feel free to let me know in the comments and I'll do my best to fix the issue.

OTHER TIPS

I don't have a IIS6 server, however, through some searching, I found that:

  1. IIS6 uses %SystemRoot%\system32\inetsrv\MetaBase.xml and %SystemRoot%\system32\inetsrv\MBSchema.xml for storing configuration (The IIS Metabase (IIS 6.0));
  2. If your server isn't changing home-directories too often, those xml should be updated;
  3. using a command line parser (like xmlstartlet), you can extract Path property from IIsWebVirtualDir node (according Metabase Structure), using XPath.

With xmlstartlet, a command like below, would output root path:

xml sel -t -v "//IIsWebVirtualDir[@Location='/LM/W3SVC/1/ROOT']/@Path" "%SystemRoot%\system32\inetsrv\MetaBase.xml"

Maybe schema needs to be corrected. This can be a command line approach. I can't test it as I don't have any IIS6 server neither I can get any MetaBase.xml sample.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top