【问题标题】:Check IIS Application pool if its empty (C# / IIS6)检查 IIS 应用程序池是否为空(C#/IIS6)
【发布时间】:2010-06-09 07:54:02
【问题描述】:

我们正在构建一个安装工具,它可以通过配置文件安装应用程序。涉及到很多 IIS,我们主要使用 WMI 来完成这项工作。最近我们发现其中 2 个应用程序使用相同的网站和应用程序池。我可以检查该网站以查看它是否包含任何 VDirs,如果它为空,则将其删除(在卸载时)。现在我想对应用程序池做同样的事情:只要它包含任何我想跳过卸载任务并让其他应用程序的卸载处理它的网站。

是否可以查看应用程序池中是否有任何网站?我只想知道它是否为空。

谢谢

【问题讨论】:

    标签: c# .net iis wmi


    【解决方案1】:

    我认为下面的代码可以帮助到你:

      static bool AppPoolIsShared(string appPoolName)
      {
         DirectoryEntry appPool = new DirectoryEntry(string.Format("IIS://localhost/w3svc/AppPools/{0}", appPoolName));
         if (appPool != null)
         {
            try
            {
               object[] appsInPool = (object[])appPool.Invoke("EnumAppsInPool", null);
               if (appsInPool != null && appsInPool.Length > 1)
               {
                  return true;
               }
            }
            catch
            {
               return true;
            }
         }
    
         return false;
      }
    

    当然,您可以根据需要调整行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-29
      • 2011-09-26
      • 2013-09-28
      • 2011-11-18
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 2014-04-19
      相关资源
      最近更新 更多