list all host headers iis

source: http://weblogs.asp.net/robmcm/archive/2005/10/04/426632.aspx

    Option Explicit
    On Error Resume Next

    Dim objBaseNode, objChildNode
    Dim objBindings, intBindings
    Dim objFSO, objFile, strOutput

    ' get a base object
    Set objBaseNode = GetObject("IIS://LOCALHOST/W3SVC")
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("HostHeaders.txt")

    ' check if we have an error ...
    If (Err.Number <> 0) Then

        ' ... and output the error.
        strOutput = "Error " & Hex(Err.Number) & "("
        strOutput = strOutput & Err.Description & ") occurred."

    ' ... otherwise, continue processing.
    Else

        ' loop through the child nodes
        For Each objChildNode In objBaseNode

            ' is this node for a web site?
            If objChildNode.class = "IIsWebServer" Then

                ' get the name of the node
                strOutput = strOutput & "LM/W3SVC/" & _
                    objChildNode.Name

                ' get the server comment
                strOutput = strOutput & " (" & _
                    objChildNode.ServerComment & ")" & vbCrLf

                ' get the bindings
                objBindings = objChildNode.ServerBindings

                ' loop through the bindings
                For intBindings = 0 To UBound(objBindings)
                    strOutput = strOutput & vbTab & _
                        Chr(34) & objBindings(intBindings) & _
                        Chr(34) & vbCrLf
                Next
            End If

        ' try not to be a CPU hog
        Wscript.Sleep 10
        Next

    End If

    objFile.Write strOutput
    objFile.Close

    Set objBaseNode = Nothing
    Set objFSO = Nothing

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.