2010-06-09 122 views
0

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

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

谢谢

回答

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

当然,你可以调整行为,以您的需求。