Finding the Metabase Path when Given the URL
When IIS servers host a lot of Web sites, a Web site adminstrator might not remember the metabase path of each site or virtual directory.
This example shows you how to use the JScript programming language to convert from a URL to a metabase path on the local IIS server.
This example uses ADSI.
var url = WScript.Arguments( 0 );
// Regular expression to separate server, host and vdir from the server binding.
var re = /^(?:http\:\/\/)?(?:([0-9a-zA-Z\._-]+)(?:\:([0-9]+))?)(\/[^:]+)?$/i;
var pieces = url.match( re );
var server = pieces[1];
var port = pieces[2];
var vdir = pieces[3];
if ( port == null || port == "" )
{
port = "80";
}
WScript.Echo( "Server : " + server );
WScript.Echo( "Port : " + port );
WScript.Echo( "Vdir : " + vdir );
// Iterate through all Web sites looking for that server binding.
var result = null;
var bFound = false;
var w3svc = GetObject( "IIS://localhost/w3svc" );
var e = new Enumerator( w3svc );
for(; ! e.atEnd(); e.moveNext() )
{
var site = e.item();
if ( site.Class != "IIsWebServer" )
continue;
//
// Iterate through all bindings for this site.
//
var bindings = site.ServerBindings.toArray();
for( var i = 0; i < bindings.length; i++ )
{
var binding = bindings[i].split( ":" );
if ( port == binding[1] &&
server.toUpperCase() == binding[2].toUpperCase() )
{
bFound = true;
break;
}
}
if ( bFound )
{
// Look for vdir now.
WScript.Echo( "Found binding on site " + site.Name );
//result = LookupVdir( site, vdir );
if ( result != null )
break;
}
}
if ( result != null )
{
WScript.Echo( "Found: " + result );
}
else
{
WScript.Echo( "Couldn't find match!" );
}
function LookupVdir( site, vdir )
{
var vdirFragment = vdir;
while( vdirFragment.length > 0 )
{
try
{
}
catch( e )
{
}
}
}