Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerating Application Pools in IIS

I am wondering if there is a way to enumerate the collection of applications pools (not the applications in a given pool - but the pools themselves) on the local IIS server using ASP.net 3.5 without the use of WMI, and if so can someone provide a link or example to how this is done?

(I forgot to add the IIS version is 6.0).

like image 753
Streklin Avatar asked Sep 09 '09 15:09

Streklin


2 Answers

Another way that might be helpful.

using System.IO;
using Microsoft.Web.Administration;

namespace AppPoolEnum
{
    class Program
    {
        static void Main(string[] args)
        {   
                foreach (var appPool in  new ServerManager().ApplicationPools)
                {
                    Console.WriteLine(appPool.Name);
                }
        }
    }
}
like image 120
Niederee Avatar answered Sep 19 '22 08:09

Niederee


This should help:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;

namespace AppPoolEnum
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryEntries appPools = 
                new DirectoryEntry("IIS://localhost/W3SVC/AppPools").Children;

            foreach (DirectoryEntry appPool in appPools)
            {
                Console.WriteLine(appPool.Name);
            }
        }
    }
}

I should also add this won't work in partial trust.

like image 42
Kev Avatar answered Sep 18 '22 08:09

Kev