Providing Additional Host Headers

Applies To: Windows Server 2003, Windows Server 2003 with SP1

Many users request additional host headers, such as contoso.com, without the www prefix. You can use Adsutil.vbs to set host headers, but you need to specify the site identification (ID). Although you can find out the site ID by parsing it from Adsutil.vbs output, an easier way is to integrate the Translate.js command-line script, which uses the IIS Windows Management Instrumentation (WMI) provider, into your Adsutil.vbs command. For more information about the IIS WMI provider, see IIS WMI Provider on MSDN.

The Translate.js script appears below. Copy it exactly as it is shown, and then save it in the same location as your other scripts. If you do not specify a location, it will be saved to C:\Windows\System32 by default. You need to use CScript.exe to run Translate.js. For information about using CScript.exe, see Adding Temporary Content.

TRANSLATE.JS
var serverComment = WScript.Arguments(0);
var query = "SELECT Name, ServerComment FROM IIsWebServerSetting WHERE ServerComment='" + serverComment + "'";
var providerObj = GetObject("winmgmts:/root/MicrosoftIISv2");
var sites = providerObj.ExecQuery(query);

if (sites.Count != 0)
{
   for(e = new Enumerator(sites); ! e.atEnd(); e.moveNext())
   {
      var item = e.item();
      // Print the site ID only by leaving the "W3SVC/" prefix out.
      WScript.Echo(item.Name.substr(6));
   }
}
else
{
   WScript.Echo("No sites found.");
}

After you save Translate.js, you can integrate it with Adsutil.vbs to provide additional host headers. Listing 9.5 uses 80:contoso.com to designate the site IP binding as All Unassigned. If you want to designate a specific IP address, type the IP address followed by a colon (:) in front of this string, as in IPAddress:80:contoso.com.

Listing 9.5   Sample Script for Setting Up Host Headers

cscript //nologo translate.js "CONTOSO.COM" > siteid.txt
 
for /f %%I in (siteid.txt) do SET SITEID=%%I

Adsutil set w3svc/%SITEID%/serverbindings ":80:WWW.CONTOSO.COM" ":80:CONTOSO.COM"

Del siteid.txt

Providing Additional Host Headers Remotely

Important

To provide additional host headers remotely while logged in with a domain account, you must have administrative credentials on both computers. When logged in with a local user account, you must have an account with the same user name and password on the remote computer, as well as administrative credentials on both computers.

To modify Translate.js to access a remote server, add the server name when you get the object by changing GetObject(winmgmts:/root/MicrosoftIISv2); to GetObject(winmgmts://Server/root/MicrosoftIISv2);, where Serveris the name of the remote server.