Hi All,

I'm trying to do 2 things with the .NET System.DirectoryServices namespace
and have hit a wall.  I'm trying to  1. Recurse the metabase looking for all
top-level domains    2. While recursing the metabase determine if someone
has set the logfiledirectory variable within the particular domain, if not
it inherits from the root /LM/W3SVC  logfiledirectory value.

This has turned out to be more of a challenge that I expected and there
isn't any examples in the DOCS or on the web.   I can go directly against
the metabase with this code snippet below to obtain the proeprty.
However trying to recurse the metabase is another challenge.     There is a
code snippet below that was a vbscript file at one point that does recurses
but doesn't use System.DirectoryServices namespace.  I tried bring back a
collection of the /LM/W3SVC which the .NET doc's say but its NULL.
However the server I was going after had 6 top-level domains.   The biggest
challenge is trying to use the DirectoryEntry object to recurse, it seems to
be ok using traditional ADSI.    Here is the code I've been working with,
appreciate any assistance someone has

Here is C# code that gets one property.
using System;
using System.DirectoryServices;
//our custom namespace
namespace myNamespace
{

 //our custom class
 public class domain
 {
  public domain(string logpath)
  {
   logPath = logpath;
  }

  //some member variables
  private string logPath;
  public string LogPath
  {
   get {return logPath;}
   set {logPath=value;}
  }

  public string C(string domainName, string logPath)
  {
   string strPath = "IIS://TopLevelDomainName/" + logPath;
   System.DirectoryServices.DirectoryEntry ds = new DirectoryEntry(strPath);
   object s = ds.Properties["LogFileDirectory"].Value;
   return s.ToString();
  }
VB.NET winform I wrote with a button event to try recurse through the
metabase
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
       Dim entry As DirectoryEntry = New
DirectoryEntry("IIS://localhost/W3SVC/")
       RecurseObj(entry)
    End Sub


    Sub RecurseObj(ByVal IISObj)
        Dim oSubDir, fRecurse, oTemp
        'On Error Resume Next
        fRecurse = False
        Select Case IISObj.Class
            Case "IIsWebFile"
                ' SetMappings(IISObj)
            Case "IIsWebServer", "IIsWebDirectory", "IIsWebVirtualDir",
"IIsWebService"
                SetMappings(IISObj)
                fRecurse = True
        End Select


        If fRecurse Then
            For Each oSubDir In IISObj
                RecurseObj(oSubDir)
            Next
        End If
    End Sub


    Sub SetMappings(ByVal IISObj)
        Dim entry As DirectoryEntry = New
DirectoryEntry("IIS://localhost/W3SVC/3")
        Console.Write(entry.Properties("ServerComment").Value & vbCrLf)
    End Sub }}

*  ----------------------------------------- *
*  Steve Schofield
*  [EMAIL PROTECTED]
*
*  Microsoft MVP - ASP.NET
*  http://www.aspfree.com
*  ----------------------------------------- *

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to