Is there a way to add subdomains to IIS 6.0 programatically?

Posted on 2005-04-13
Last Modified: 2008-01-09

I'll have to add about 150 subdomains to a top level domain. Before starting to do this manually I'd like to know if there's a way to do it programatically -> passing values and parameters from a SQL Server Database.

I was looking for examples on the internet but have nothing found yet.

Does anyone have an idea? Or some links that explain how to do this programatically?

VB6, VBScript, VB.NET or C# hints or examples are very much appreciated!

Best regards,
Question by:Raisor
    LVL 1

    Accepted Solution

    This might help you out.

    it goes through customizing deployment of apps on IIS.

    should allow you to automate the process with .NET and SQL.

    hope this helps.
    LVL 15

    Author Comment


    Thanks a lot for the provided link that is also giving some source code to understand the basics of doing what I'm up to do!

    Another thing that the provided link did was to give me an understanding on what I'll have to look for to make things even easier than to go with VB.NET:

    Public Overrides Sub Install(ByVal stateSaver As _
        Dim strVDir As String = Me.Context.Parameters.Item("VDir")
        Dim intServerNum As Integer = _
        Dim strObjectPath As String = "IIS://" & _
        System.Environment.MachineName & "/W3SVC/" & _
        intServerNum.ToString & "/ROOT/" & strVDir
        Dim IISVdir As Object

        ' Gets the IIS VDir Object.
        IISVdir = GetIISObject(strObjectPath)

        ' Set the AuthAnonymous property here.
        IISVdir.AuthAnonymous = False

        ' Uses SetInfo to save the settings to the Server.
    End Sub

    What I found, using the information you've provided was infact a C#.NET approach that I'll try to leverage:

    public class SetupUtility{public SetupUtility(){}public int CreateWebSite(string webSiteName, string pathToRoot){return CreateWebSite(webSiteName, pathToRoot, false);}public int CreateWebSite(string webSiteName, string pathToRoot, bool createDir){DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");// Find unused ID value for new web siteint siteID = 1;foreach(DirectoryEntry e in root.Children){if(e.SchemaClassName == "IIsWebServer"){int ID = Convert.ToInt32(e.Name);if(ID >= siteID){siteID = ID+1;}}}// Create web siteDirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);site.Invoke("Put", "ServerComment", webSiteName);site.Invoke("Put", "KeyType", "IIsWebServer");site.Invoke("Put", "ServerBindings", ":80:");site.Invoke("Put", "ServerState", 2);site.Invoke("Put", "FrontPageWeb", 1);site.Invoke("Put", "DefaultDoc", "Default.aspx");site.Invoke("Put", "SecureBindings", ":443:");site.Invoke("Put", "ServerAutoStart", 1);site.Invoke("Put", "ServerSize", 1);site.Invoke("SetInfo");// Create application virtual directoryDirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");siteVDir.Properties["AppIsolated"][0] = 2;siteVDir.Properties["Path"][0] = pathToRoot;siteVDir.Properties["AccessFlags"][0] = 513;siteVDir.Properties["FrontPageWeb"][0] = 1;siteVDir.Properties["AppRoot"][0] = "LM/W3SVC/"+siteID+"/Root";siteVDir.Properties["AppFriendlyName"][0] = "Root";siteVDir.CommitChanges();site.CommitChanges();return siteID;}}

    ... as soon as I have a "working" solution I'll share the peace of code that does what I'm up to do!

    Thanks a lot for your help, karlossos ...

    Best regards,
    LVL 15

    Author Comment


    Just an addon for anyone reading the C#.NET approach: I've found it at

    ... there are some useful diffs to the presented code there!

    Best regards,

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    A short article about problems I had with the new location API and permissions in Marshmallow
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now