« Previous Next »

Thread: Add Application Pool To A Website

Last post 12-30-2008 1:18 PM by Paul Lynch. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 12-29-2008, 2:47 PM

    Add Application Pool To A Website

    I have a script that creates a website and app pool. How do I use vbscript to assign that app pool to the iis website thats created?

     

    Here is the current script I'm using. If I need a second script thats fine. But I can't seem to get it to work to add app pool to the website. 

     Thanks!!

     var objAppPools = GetObject("IIS://localhost/W3SVC/AppPools");
    var objAppPool = objAppPools.Create("IIsApplicationPool", "MyAppPool1");
    objAppPool.IdleTimeout = 20;
    objAppPool.SetInfo();
    objAppPool.Start();





    var Web           = "TitanExample";           //name of the website

    var ServerBinding = ":80:";   //ip address and portnumber

    var strDomain     = "domain.com";
    var sRootDir      = "C:\\sites\\";       //place of the site


    CreateWeb(Web,sRootDir,Web);


    function CreateWeb( sHostName, sRootDir, comments )
    {
     var oWeb = GetObject("IIS://localhost/W3SVC");
     oWeb.GetInfo();

     //looks for the first free website and create it
     var Index = 1;
     var cont  = 0;

     while( cont == 0 )
     {
      try
      {
        var webobj = GetObject("IIS://localhost/w3svc/" + Index);
      }
      catch( e )  
      {
        if( ( e.number & 0xFFFF ) > 0 )
        {
          cont= 1;
        }
      }
      Index = Index + 1;
     }
     Index = Index - 1;
     WScript.Echo( "Next Index: " + Index );

     WScript.Echo("creating web " + sHostName);
     oServer = oWeb.Create("IIsWebServer",Index);

     //Configure the new server
     oServer.DefaultDoc        = "default.asp, login.asp";
     oServer.ServerComment     = comments;
     oServer.ConnectionTimeout = 600;
     oServer.ServerBindings    = ServerBinding + sHostName;



    oServer.SetInfo();


     var fs    = new ActiveXObject("Scripting.FileSystemObject");
     if( !fs.FolderExists( sRootDir ) )
      var foldr = fs.CreateFolder(sRootDir);

     //Create virtual root directory for the new site
     oServer   = GetObject("IIS://localhost/w3svc/" + Index );
     var oVdir = oServer.Create("IIsWebVirtualDir", "ROOT");

     //Configure the virtual root directory
     oVdir.Path         = sRootDir;
     oVdir.AccessRead   = "True";
     oVdir.AccessWrite  = "True";
     oVdir.AccessScript = "True";




     oVdir.SetInfo();

     //Starting the website
     WScript.Echo("starting web " + sHostName + " " + Index);
     oServer.Start();





    } //end function

  • 12-29-2008, 6:13 PM In reply to

    • thomad
    • Top 25 Contributor
    • Joined on 08-20-2002, 11:28 AM
    • Redmond
    • Posts 503

    Re: Add Application Pool To A Website

    Here you go:

    oRootApp = GetObject("IIS://localhost/w3svc/" + Index + "/root");

    oRootApp.AppPoolId = "MyAppPool1";

    oRootApp.SetInfo();

    Hope this helps

    Thomas Deml
    Program Manager
    Internet Information Services
    Microsoft Corp.
  • 12-29-2008, 6:16 PM In reply to

    Re: Add Application Pool To A Website

     Awesome thanks!!

     

    Do you know how i can make the asp.net version 3.5 to be selected?

  • 12-29-2008, 9:08 PM In reply to

    • thomad
    • Top 25 Contributor
    • Joined on 08-20-2002, 11:28 AM
    • Redmond
    • Posts 503

    Re: Add Application Pool To A Website

    Not sure what you are asking for. ASP.NET 3.5 is just a feature pack on top of 2.0. You can map an application to ASP.NET 2.0/3.5 by running aspnet_regiis.exe. In IIS 6.0 there is no good way to do this by changing configuration. In IIS7 you can set the managedRuntimeVersion property.

    Hope this helps

    Thomas Deml
    Program Manager
    Internet Information Services
    Microsoft Corp.
  • 12-30-2008, 9:35 AM In reply to

    Re: Add Application Pool To A Website

     I don't want to do with aspnet_regiis.exe as I'm only wanting to target certain sites as they are created with the script. Im unsure how to pass the site id onto the aspnet_regiis.exe as the vbscript runs?

  • 12-30-2008, 10:40 AM In reply to

    Re: Add Application Pool To A Website

    skillednerd:

     I don't want to do with aspnet_regiis.exe as I'm only wanting to target certain sites as they are created with the script. Im unsure how to pass the site id onto the aspnet_regiis.exe as the vbscript runs?

     

    You have to use aspnet_regiis.exe to do this in IIS 6.0, there is no other (supported) method of configuring the Framework version. You could try to determine the web site ID using a script such as this :

    http://www.gafvert.info/iis/article/cs_find_id_by_name.htm

    Regards, 

    Paul Lynch | www.iisadmin.co.uk
  • 12-30-2008, 11:04 AM In reply to

    Re: Add Application Pool To A Website

     I got it all to work. I found another script and added part so all works including adding the asp.net version. here is full script that is working.

     

    Option Explicit

    Dim sSiteID, sRegion, sWebSiteName, sOrgName, sIntIPAddress, objAppPools, objApplication
    Dim sWebPath, objIIS, strWebID, ObjServerBindings, objWebSite, objPublic
     Dim i, ScriptMaps, arrVersions(2), thisVersion, thisScriptMap


    sSiteID = "SampleSite"
    sRegion = "US"
    sIntIPAddress = ""
    sWebPath = "C:\\site\\website\\"

    'Create Application Pool
    Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
    Set objAppPools = objAppPools.Create("IIsApplicationPool", sSiteID)
    objAppPools.SetInfo

    'Create Web Site
    set objIIS = GetObject("IIS://localhost/W3SVC")
    objServerBindings = Array(0)
    objServerBindings(0) = sIntIPAddress & ":" & 80 & ":" & ""

    strWebID = objIIS.CreateNewSite(sSiteID, objServerBindings, sWebPath)
    WScript.Echo strWebID

    'Sets Web Site Properties
    set objWebSite = GetObject("IIS://localhost/W3SVC/" & strWebID)
    objWebSite.AccessRead = "True"
    objWebsite.AccessScript = "True"




    'ObjWebsite.AppPoolID = sSiteID
    'objWebsite.AppFriendlyName = "Default Application"




    objWebSite.SetInfo



    Set objApplication = GetObject("IIS://localhost/W3SVC/" & strWebID & "/ROOT")
        With objApplication
            .AppPoolID = sSiteID
          '  .AppRoot = "IIS://localhost/LM"
            .AppFriendlyName = "Default Application"
            .AppIsolated = 1
            .AccessRead = True
            .AccessExecute = True
            .SetInfo
        End With







    Call Main()

    '-----------------------------------
    ' Name: Main
    ' Description: Bulk of page is in a subroutine so that we can
    '              Exit early if desired
    '-----------------------------------
    Sub Main()
       
        Dim strServer
        Dim intSiteID
        Dim strVDir

        strServer = "localhost"
        intSiteID = strWebID
       
       
       





       
        If strVDir <> "" Then
            strVDir = "/" & strVDir
        End If

        Dim strNewVersion
        strNewVersion = "v2.0.50727"
       
        Dim strObjPath
        Dim objIIS
       
        'make a backup first
        Backup(strServer)

        strObjPath = "IIS://localhost/W3SVC/" & intSiteID & "/ROOT"
        Set objIIS = getObject(strObjPath)
       
       
        ReplaceScriptMaps objIIS, strNewVersion
           
        Set objIIS = Nothing
    End Sub


    '-----------------------------------
    ' Name: ReplaceScriptMaps
    ' Description: Set the script mappings to the new version
    ' Inputs: objIIS, strNewVersion
    '-----------------------------------
    Sub ReplaceScriptMaps(objIIS, strNewVersion)
        Dim i, ScriptMaps, arrVersions(2), thisVersion, thisScriptMap
        Dim strSearchText, strReplaceText
       


        Select Case Trim(LCase(strNewVersion))
            Case "v1.1.4322"
                strReplaceText = "v2.0.50727"
            Case ""
                strReplaceText = "v2.0.50727"

               Case Else
       
                strReplaceText = "v2.0.50727"

        End Select


        ScriptMaps = objIIS.ScriptMaps

        arrVersions(0) = "v1.1.4322"
        arrVersions(1) = "v2.0.50727"


        'Loop through all three potential old values
        For Each thisVersion in arrVersions

            'Loop through all the mappings
            For thisScriptMap = LBound(ScriptMaps) to UBound(ScriptMaps)

                'Replace the old with the new   
                ScriptMaps(thisScriptMap) = Replace(ScriptMaps(thisScriptMap), thisVersion, strReplaceText)
            Next
        Next   

       
        objIIS.ScriptMaps = ScriptMaps
        objIIS.SetInfo
        WScript.Echo("Set new Script Maps successfully.")

    End Sub   


    '-----------------------------------
    ' Name: Backup
    ' Description: Backup the metabase
    ' Inputs: strServer (friendly name of the version)
    '-----------------------------------
    Sub Backup(strServer)
        Dim objComp
        Set objComp = GetObject("IIS://" & strServer)
        objComp.Backup "", &HFFFFFFFF, 2

    End Sub

  • 12-30-2008, 1:18 PM In reply to

    Re: Add Application Pool To A Website

    That's great. Thanks for sharing your solution as well.

    Regards, 

    Paul Lynch | www.iisadmin.co.uk
Page 1 of 1 (8 items)
Microsoft Communities