简体   繁体   English

检查IIS应用程序池是否为空(C#/ IIS6)

[英]Check IIS Application pool if its empty (C# / IIS6)

We're building an installation tool which can install applications by a configuration file. 我们正在构建一个可以通过配置文件安装应用程序的安装工具。 There is a lot of IIS involved and we mostly use WMI for the job. 涉及很多IIS,我们主要使用WMI来完成这项工作。 Recently we discovered that 2 of the applications use the same website and application pool. 最近,我们发现其中两个应用程序使用相同的网站和应用程序池。 I can check the website to see if it contains any VDirs and delete it (while uninstalling) if its empty. 我可以检查该网站以查看其是否包含任何VDirs,如果其为空,则将其删除(在卸载时)。 Now I want to do the same thing with the application pool: as long as it contains any websites I want to skip the uninstallationtask and let the other application's uninstall handle it. 现在,我想对应用程序池做同样的事情:只要它包含任何网站,我都想跳过卸载任务,让另一个应用程序的卸载来处理它。

Is it possible to see if there are any websites in an application pool? 是否可以查看应用程序池中是否有任何网站? All I want to know is if its empty or not. 我只想知道它是否为空。

Thank you 谢谢

I think the following code can help you: 我认为以下代码可以为您提供帮助:

  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;
  }

Of course, you can adjust the behavior to your needs. 当然,您可以根据自己的需要调整行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM