Enumerating the Names of IIS Web Sites Using WSH

This article was previously published under Q197891
This article has been archived. It is offered "as is" and will no longer be updated.
We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:
When you use the Windows NT Option Pack (NTOP) and Internet InformationServer (IIS) version 4.0, Web sites are added to the server using theMicrosoft Management Console (MMC). Each new Web site is given a number inthe metabase, and this number is used by IIS when logging and FrontPagewhen installing extensions. It is sometimes desirable to know which numbercorresponds to a given Web site.
More information
The following code was written using Windows Script Host (WSH) andlists all Web sites by their short metabase path and name.

To use this script, follow these steps:
  1. Copy the following code into Notepad, and then save it to your computer as a file called W3sites.vbs:
          Dim objW3SVC, objSITE, strOUT      Set objW3SVC = GetObject("IIS://LOCALHOST/W3SVC")      If (Err <> 0) Then      strOUT = "Error " & Hex(Err.Number) & "("      strOUT = strOUT & Err.Description & ") occurred."      Else      For Each objSITE In objW3SVC      If objSITE.class = "IIsWebServer" Then      strOUT = strOUT & "LM/W3SVC/" & objSITE.Name & Chr(9)      strOUT = strOUT & Chr(34) & objSITE.ServerComment      strOUT = strOUT & Chr(34) & Chr(13) & Chr(10)      End If      Next      End If      WScript.Echo strOUT						
  2. To run the code, open a command prompt, and then type the following command:
          CSCRIPT.EXE W3SITES.VBS 						

Article ID: 197891 - Last Review: 10/26/2013 11:18:00 - Revision: 4.0

  • kbnosurvey kbarchive kbhowto KB197891