开发者

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. 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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜