使用ADSI获取IIS应用程序池列表,C#源代码示例

来源:互联网 发布:淘宝优惠卷群怎么赚钱 编辑:程序博客网 时间:2024/05/30 23:00

 

            ApplicationPool[] AppPools = IISHelper.GetApplicationPools();
            
foreach (ApplicationPool pool in AppPools)
            
{
                Console.WriteLine(pool.Name);
            }

 

        /// <summary>
        
/// 获取应用程序池->数组
        
/// </summary>
        
/// <returns></returns>

        public ApplicationPool[] GetApplicationPools()
        
{
            
if ((SiteInfo.ServerType != WebServerTypes.IIS6) && (SiteInfo.ServerType != WebServerTypes.IIS7)) return null;
            DirectoryEntry directoryEntry 
= GetDirectoryEntry("IIS://LOCALHOST/W3SVC/AppPools");
            
if (directoryEntry == nullreturn null;
            List
<ApplicationPool> list = new List<ApplicationPool>();
            
foreach (DirectoryEntry entry2 in directoryEntry.Children)
            
{
                PropertyCollection properties 
= entry2.Properties;
                ApplicationPool pool 
= new ApplicationPool();
                pool.Name 
= entry2.Name;
                list.Add(pool);
            }

            
return list.ToArray();
        }

 

    /// <summary>
    
/// 应用程序池
    
/// </summary>

    public class ApplicationPool
    
{

        
/// <summary>
        
/// 版本
        
/// </summary>

        public string DotNetVersion = "v2.0.50727";
        
/// <summary>
        
/// 应用程序池名
        
/// </summary>

        public string Name = "";
    }