2010-06-09 126 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; 
    } 

當然,你可以調整行爲,以您的需求。