Q:

listing virtual directories in IIS 6.0 - C#

I have written a Windows Application.My question is:I have been listing virtual directories in IIS 6.0  with through code as below.I have to find pyhsical path of the virtual directory that are selected.
  Also,DirectoryEntry class has a property called properties. But,I can't use it. Lastly,I getting the following the error.
   The directory cannot report the number of properties

Code:
  try

  {

  string serverName = "localhost";

  string VirDirSchemaName = "IIsWebVirtualDir";

  iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1");

  DirectoryEntry folderRoot = iisServer.Children.Find("Root",VirDirSchemaName);

  return folderRoot.Children;

  }

  catch (Exception e)

  {

  throw new Exception("Error while retrieving virtual directories.",e);

  }

A:

why don't you use WMI
 using System.DirectoryServices;

    private DirectoryEntry _iisServer = null;
    private DirectoryEntry iisServer
    {
        get
        {
            if (_iisServer == null)
            {
                string path = string.Format("IIS://{0}/W3SVC/1", serverName);
                _iisServer = new DirectoryEntry(path);
            }
            return _iisServer;
        }
    }

    private IDictionary<string, DirectoryEntry> _virtualDirectories = null;
    private IDictionary<string, DirectoryEntry> virtualDirectories
    {
        get
        {
            if (_virtualDirectories == null)
            {
                _virtualDirectories = new Dictionary<string, DirectoryEntry>();

                DirectoryEntry folderRoot = iisServer.Children.Find("Root", VirDirSchemaName);
                foreach (DirectoryEntry virtualDirectory in folderRoot.Children)
                {
                    _virtualDirectories.Add(virtualDirectory.Name, virtualDirectory);
                }
            }
            return _virtualDirectories;
        }
    }

List all virtual directories in IIS 5,6 and 7

