本帖最后由 HeddaZ 于 2012-02-21 17:35:31 编辑

解决方案 »

  1.   

    为神马没人回答呀?
    另外读注册表中有信息吗?会不会涉及到WIN7/WIN2008的权限问题?
      

  2.   

    ApplicationPool 在 Microsoft.Web.Administration.dll 中(.NET Framework 3.5)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 == null) return 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 = "";
        }
     
      

  3.   

    果然很生僻/需要添加应用程序池空间引用
    using System.DirectoryServices; string method="Start"; //Start开启  Recycle回收  Stop 停止
       string AppPoolName = "chengxuchiname";
       try
       {    
          DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
          DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");
          findPool.Invoke(method,null);
          appPool.CommitChanges();
          appPool.Close();
        MessageBox.Show("应用程序池名称启动成功","启动成功"); 
       }
       catch(Exception ex)
       {
        MessageBox.Show(ex.Message,"启动失败");      
       }//获取应用程序池列表 等操作
      /// <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 == null) return 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 = "";
        }连接
      

  4.   

    不好意思上面好像实现不了你效果http://msdn.microsoft.com/zh-cn/library/microsoft.web.administration.applicationpool.aspx你己己研究下  
      

  5.   

    再谢一下,至此我已经搞定了。确实可以得到这个属性值,为更多人参考拿出来分享下:DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                DirectoryEntry findPool = appPool.Children.Find("Prodika v6.1.1.0", "IIsApplicationPool");            string b = "";
                foreach (string a in findPool.Properties.PropertyNames)
                {
                    b += string.Format("{0}={1}\n", a, findPool.InvokeGet(a));
                }            return b;可以得到如下值,其中就有我要的:
    AppPoolIdentityType=0
    AppPoolState=2
    Win32Error=0
    AppPoolCommand=1
    KeyType=IIsApplicationPool
    AppPoolAutoStart=True  
    Enable32BitAppOnWin64=True  //我就是要这个
    ManagedPipelineMode=1★★注意,启动进程池的账号必须有‘管理员’权限,否则会报 access is denied.