How to read the directory structure of IIS 6 sites using WMI?

I need to read website folders using WMI and C # in IIS 6.0. I can read virtual directories and applications using the "IISWebVirtualDirSetting" class. However, the physical folders located inside the website cannot be read using this class.

And for my case, I need to read the subfolders located on the website , and then set permission for them. For my requirement, I do not need to work with virtual directories / web services applications (which can be easily obtained using the code below ..).

I tried using the IISWebDirectory class, but it was useful.

Here is the code that reads the IIS virtual directories ...

public static ArrayList RetrieveVirtualDirList(String ServerName, String WebsiteName) { ConnectionOptions options = SetUpAuthorization(); ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options); scope.Connect(); String SiteId = GetSiteIDFromSiteName(ServerName, WebsiteName); ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IISWebVirtualDirSetting"); //ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting"); ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery); ArrayList WebSiteListArray = new ArrayList(); ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get(); String WebSiteName = String.Empty; foreach (ManagementObject WebSite in WebSitesCollection) { WebSiteName = WebSite.Properties["Name"].Value.ToString(); WebsiteName = WebSiteName.Replace("W3SVC/", ""); String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/')); String temp = WebsiteName.Substring(0, WebsiteName.IndexOf('/') + 1); String VirtualDirName = WebsiteName.Substring(temp.Length); WebsiteName = WebsiteName.Replace(SiteId, ""); if (extrctedSiteId.Equals(SiteId)) //if (true) { WebSiteListArray.Add(VirtualDirName ); //WebSiteListArray.Add(WebSiteName); //+ "|" + WebSite.Properties["Path"].Value.ToString() } } return WebSiteListArray; } 

PS:

I need to programmatically retrieve subfolders of already deployed site (s) using WMI and C # in ASP.NET Application. I need to find subfolders of existing websites on a local or remote IIS 6.0 web server. Therefore, I require a software solution. Exactly, if I pointed to the correct class (for example, IISWebVirtualDirSetting, etc.), which I can use to get a list of physical folders on the website, then it will be very useful.

I do not work in Powershell, and I really don't need a solution that includes powershell or vbscripts.

Any alternative software way to do the same in C # / ASP.Net will also be highly appreciated.

EDIT:

GetSiteIdFromSiteName

The code might look like this:

 public static int GetSiteIdFromSiteName(String ServerName, String WebsiteName) { ConnectionOptions options = SetUpAuthorization(); ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options); scope.Connect(); ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting"); ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery); ArrayList WebSiteListArray = new ArrayList(); ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get(); String WebSiteName = String.Empty; foreach (ManagementObject WebSite in WebSitesCollection) { WebSiteName = WebSite.Properties["Name"].Value.ToString(); WebsiteName = WebSiteName.Replace("W3SVC/", ""); String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/')); break; } return extrctedSiteId; } 

and

SetupAuthorization ()

Here is the SetupAuthorization function.

  public ConnectionOptions SetUpAuthorization() { ConnectionOptions options = new ConnectionOptions(); //options.Authentication = AuthenticationLevel.Connect; //may need to set Packetprivacy enum options.Authentication = AuthenticationLevel.PacketPrivacy; options.EnablePrivileges = true; options.Impersonation = ImpersonationLevel.Impersonate; return options; } 

Hi

+4
source share
2 answers

Nothing. I got it myself. If the directory structure is on the local system, then System.IO.DirectoryInfo is required. Using remote access can be used for a remote server.

Help: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx

If WMi should be there, then Win32_Directory is the class that should be used in the request:

 "Select * from Win32_directory where drive ='"+ DriveLetter +":' and Path ='%" + MyPath + "%'"; 

Help: http://msdn.microsoft.com/en-us/library/aa394130(VS.85).aspx

+2
source

Have you looked at the Web Deployment Tool?

http://www.iis.net/expand/WebDeploy

Ability to host ACL, COM, GAC and registry lists.

-1
source

Source: https://habr.com/ru/post/1305190/


All Articles