Previous Next

Thread: Get Application Pool names in IIS7

Last post 09-10-2008 5:16 AM by satya.ambatipudi. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 09-09-2008, 3:44 AM

    Get Application Pool names in IIS7

    hi ,

    i want to get application pool names using C# and asp.net.

    follwing is the code i am using to get name..

     private void GetAppPoolNames()
        {
            System.DirectoryServices.DirectoryEntry Root = this.GetDirectoryEntry("IIS://localhost/W3SVC/AppPools");
            //DirectoryEntry Root = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
            
            if (Root == null)
            {
                Response.Write("No Child in AppPool");
            }
            else
            {
                foreach (DirectoryEntry dir in Root.Children)
                {
                    System.DirectoryServices.PropertyCollection pr = dir.Properties;
                    //ApplicationPool pool = new ApplicationPool();
                    //pool.Name = dir.Name;
                    //DropDownList1.Items.Add(pool.Name);
                    DropDownList1.Items.Add(dir.Name);
                }
            }
        }

      private DirectoryEntry GetDirectoryEntry(string path)
        {
            DirectoryEntry root = null;
            try
            {
                root = new DirectoryEntry(path);
            }
            catch
            {
                Response.Write("Could not access Node");
                return null;
            }
            if (root == null)
            {
                Response.Write("Could not access Node");
                return null;
            }
            return root;
        }

     

    But i am getting Error. COM error.

    Help plz. 

    satya
  • 09-09-2008, 10:51 AM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 561

    Re: Get Application Pool names in IIS7

    You need admin privileges to be able to read list of apppools. I tried running your program from an elevated command window and it works fine.

    Thanks,
    Kanwal

  • 09-10-2008, 5:16 AM In reply to

    Re: Get Application Pool names in IIS7

     hi,

        public void GetappName()
        {
            ServerManager mgr = new ServerManager();
            System.Collections.IEnumerator ie=   mgr.ApplicationPools.GetEnumerator();
            while (ie.MoveNext())
            {
                DropDownList1.Items.Add(((Microsoft.Web.Administration.ApplicationPool)(ie.Current)).Name);
            }
        }

    using this we can list all the app pools in iis 7  

    satya
Page 1 of 1 (3 items)
Page view counter