public IISWebServerCollection GetWebServers() { var iISWebServerCollection = new IISWebServerCollection(); IEnumerator iEnumerator1 = new DirectoryEntry("IIS://localhost/W3SVC").Children.GetEnumerator(); try { while (iEnumerator1.MoveNext()) { var directoryEntry2 = (DirectoryEntry) iEnumerator1.Current; if (directoryEntry2.SchemaClassName != "IIsWebServer") continue; var iISWebServer = new IISWebServer { iID = Convert.ToInt32(directoryEntry2.Name), sServerName = (String) directoryEntry2.Properties["ServerComment"].Value }; var directoryEntry3 = new DirectoryEntry(String.Concat("IIS://localhost/W3SVC/", iISWebServer.ID, "/Root")); iISWebServer.sRootPath = directoryEntry3.Properties["Path"][0] as String; IEnumerator iEnumerator2 = directoryEntry3.Children.GetEnumerator(); try { while (iEnumerator2.MoveNext()) { var directoryEntry4 = (DirectoryEntry) iEnumerator2.Current; if (directoryEntry4.SchemaClassName.ToUpper() == "IIsWebVirtualDir".ToUpper()) { var iISWebVirtualDirectory = new IISWebVirtualDirectory { _sPath = (String) directoryEntry4.Properties["Path"][0], _sName = directoryEntry4.Name, _isApplication = (String) directoryEntry4.Properties["AppRoot"][0] != String.Concat("/LM/W3SVC/", iISWebServer.ID, "/ROOT"), _iWebServerID = iISWebServer.ID }; iISWebServer.VirtualDirectories.Add(iISWebVirtualDirectory); } } } finally { var iDisposable = iEnumerator2 as IDisposable; if (iDisposable != null) { iDisposable.Dispose(); } } iISWebServerCollection.Add(iISWebServer); } } finally { var iDisposable = iEnumerator1 as IDisposable; if (iDisposable != null) { iDisposable.Dispose(); } } return iISWebServerCollection; }
public IISWebServerCollection GetWebServers() { var iISWebServerCollection = new IISWebServerCollection(); IEnumerator iEnumerator1 = new DirectoryEntry("IIS://localhost/W3SVC").Children.GetEnumerator(); try { while (iEnumerator1.MoveNext()) { var directoryEntry2 = (DirectoryEntry)iEnumerator1.Current; if (directoryEntry2.SchemaClassName != "IIsWebServer") { continue; } var iISWebServer = new IISWebServer { iID = Convert.ToInt32(directoryEntry2.Name), sServerName = (String)directoryEntry2.Properties["ServerComment"].Value }; var directoryEntry3 = new DirectoryEntry(String.Concat("IIS://localhost/W3SVC/", iISWebServer.ID, "/Root")); iISWebServer.sRootPath = directoryEntry3.Properties["Path"][0] as String; IEnumerator iEnumerator2 = directoryEntry3.Children.GetEnumerator(); try { while (iEnumerator2.MoveNext()) { var directoryEntry4 = (DirectoryEntry)iEnumerator2.Current; if (directoryEntry4.SchemaClassName.ToUpper() == "IIsWebVirtualDir".ToUpper()) { var iISWebVirtualDirectory = new IISWebVirtualDirectory { _sPath = (String)directoryEntry4.Properties["Path"][0], _sName = directoryEntry4.Name, _isApplication = (String) directoryEntry4.Properties["AppRoot"][0] != String.Concat("/LM/W3SVC/", iISWebServer.ID, "/ROOT"), _iWebServerID = iISWebServer.ID }; iISWebServer.VirtualDirectories.Add(iISWebVirtualDirectory); } } } finally { var iDisposable = iEnumerator2 as IDisposable; if (iDisposable != null) { iDisposable.Dispose(); } } iISWebServerCollection.Add(iISWebServer); } } finally { var iDisposable = iEnumerator1 as IDisposable; if (iDisposable != null) { iDisposable.Dispose(); } } return(iISWebServerCollection); }