Programmatically create IIS host header using VBScript / ASP?

Posted on 2010-01-02
Last Modified: 2012-06-27
I am creating a website that will run on IIS 6 and will have a lot of subdomains.  I wanted to find a method to use wildcard subdomains, but IIS doesn't seem to support this.  I only have one IP address, and host other sites on the same server so I can't dedicate an IP to this site and do the subdomain redirection programmatically.

I have created a wildcard A record in my DNS zone so,,,, etc will all resolve to the IP of my IIS server.

I need to find a way to programmatically add host headers for new subdomains to the site in IIS.  For example, I want to be able to have a setup script that I can use to add subdomains without having to manually add the host headers in IIS.  

It seems like there must be a way to modify the host headers assigned to a particular IIS website using VBScript, but I'm striking out trying to find it.
Question by:FWeston
    LVL 70

    Accepted Solution


    You may find this quite useful if you end up doing this kind of thing on a regular basis:

    Host Headers are held in the ServerBindings property, it can be set using both ADSI and WMI. The following is ADSI because the interface is generally simpler.

    Something of an untested example below, hopefully it's enough to get you started!


    ' This represents the site level node in the metabase. Properties for the site are 
    ' split between this and the "root" virtual directory beneath.
    Set objWebSite = GetObject("IIS://ServerName/W3SVC/<SiteID>")
    ' SiteID is numeric, in IIS 6 it is semi-random. IIS 5 and IIS 7 use incrementing
    ' IDs. For IIS 6 you'll either need to know this in advance, or need to search 
    ' the metabase for it. The Default Web Site has SiteID 1.
    ' To get the current ServerBindings you can call the Get method
    arrServerBindings = objWebSite.Get("ServerBindings")
    ' Also accessible with:
    arrServerBindings = objWebSite.ServerBindings
    ' Each Binding string in the array takes the form:
    ' IPAddress:PortNumber:HostName
    strNewServerBinding = ""
    ' Either extend the current array (declare a new array, with one extra element 
    ' and copy existing entries). Then a simply put the new array into the property:
    objWebSite.Put "ServerBindings", arrNewServerBindings
    ' Or use the ADS_PROPERTY_APPEND to add an entry to the existing array
    objWebSite.PutEx ADS_PROPERTY_APPEND, "ServerBindings", Array(strNewServerBinding)

    Open in new window

    LVL 3

    Author Closing Comment

    This worked perfectly.  I couldn't get the ADS_PROPERTY_APPEND method to work, but creating a new array and then saving that works just fine.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now