|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ADSI, .NET System.DirectoryServices Namespace and recursing the IIS metabase
<i><b>Originally posted by : Steve Schofield (steve@aspfree.com)</b></i><br />Hi All,<br /><br />I'm trying to do 2 things with the .NET System.DirectoryServices namespace<br />and have hit a wall. I'm trying to 1. Recurse the metabase looking for all<br />top-level domains 2. While recursing the metabase determine if someone<br />has set the logfiledirectory variable within the particular domain, if not<br />it inherits from the root /LM/W3SVC logfiledirectory value.<br /><br />This has turned out to be more of a challenge that I expected and there<br />isn't any examples in the DOCS or on the web. I can go directly against<br />the metabase with this code snippet below to obtain the proeprty.<br />However trying to recurse the metabase is another challenge. There is a<br />code snippet below that was a vbscript file at one point that does recurses<br />but doesn't use System.DirectoryServices namespace. I tried bring back a<br />collection of the /LM/W3SVC which the .NET doc's say but its NULL.<br />However the server I was going after had 6 top-level domains. The biggest<br />challenge is trying to use the DirectoryEntry object to recurse, it seems to<br />be ok using traditional ADSI. Here is the code I've been working with,<br />appreciate any assistance someone has would be appreciated.<br /><br />Here is C# code that gets one property.<br />using System;<br />using System.DirectoryServices;<br />//our custom namespace<br />namespace myNamespace<br />{<br /><br /> //our custom class<br /> public class domain<br /> {<br /> public domain(string logpath)<br /> {<br /> logPath = logpath;<br /> }<br /><br /> //some member variables<br /> private string logPath;<br /> public string LogPath<br /> {<br /> get {return logPath;}<br /> set {logPath=value;}<br /> }<br /><br /> public string C(string domainName, string logPath)<br /> {<br /> string strPath = "IIS://TopLevelDomainName/" + logPath;<br /> System.DirectoryServices.DirectoryEntry ds = new DirectoryEntry(strPath);<br /> object s = ds.Properties["LogFileDirectory"].Value;<br /> return s.ToString();<br /> }<br />VB.NET winform I wrote with a button event to try recurse through the<br />metabase<br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As<br />System.EventArgs) Handles Button1.Click<br /> Dim entry As DirectoryEntry = New<br />DirectoryEntry("IIS://localhost/W3SVC/")<br /> RecurseObj(entry)<br /> End Sub<br /><br /><br /> Sub RecurseObj(ByVal IISObj)<br /> Dim oSubDir, fRecurse, oTemp<br /> 'On Error Resume Next<br /> fRecurse = False<br /> Select Case IISObj.Class<br /> Case "IIsWebFile"<br /> ' SetMappings(IISObj)<br /> Case "IIsWebServer", "IIsWebDirectory", "IIsWebVirtualDir",<br />"IIsWebService"<br /> SetMappings(IISObj)<br /> fRecurse = True<br /> End Select<br /><br /><br /> If fRecurse Then<br /> For Each oSubDir In IISObj<br /> RecurseObj(oSubDir)<br /> Next<br /> End If<br /> End Sub<br /><br /><br /> Sub SetMappings(ByVal IISObj)<br /> Dim entry As DirectoryEntry = New<br />DirectoryEntry("IIS://localhost/W3SVC/3")<br /> Console.Write(entry.Properties("ServerComment").Value & vbCrLf)<br /> End Sub }}<br /><br /><br /><br /><br /><br />
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : steve (steve@aspfree.com)</b></i><br />using System;<br />using System.IO;<br />using System.Net.Sockets;<br />using System.Net;<br />using System.Text;<br />using System.Management;<br />using System.DirectoryServices;<br />using System.Runtime.InteropServices;<br />namespace ConsoleApplication1<br />{<br />class Class1<br />{<br />/// <summary><br />/// The main entry point for the application.<br />/// </summary><br />[STAThread]<br />static void Main(string[] args)<br />{<br />DirectoryEntry Root = new DirectoryEntry("IIS://localhost/w3svc");<br />foreach(DirectoryEntry de in Root.Children)<br />{<br />try<br />{<br />Console.WriteLine("Log file directory: " +<br />de.Properties["LogFileDirectory"].Value);<br />}<br />catch(COMException ComEx)<br />{<br />Console.WriteLine();<br />Console.WriteLine (" *** COM Error *** ");<br />Console.WriteLine( "COM Exception: " + ComEx.ErrorCode.ToString() + " " +<br />ComEx.Message );<br />Console.WriteLine (" *** COM Error *** ");<br />Console.WriteLine();<br />}<br />catch(Exception Ex)<br />{<br />Console.WriteLine();<br />Console.WriteLine ( "*** System Exception ***" );<br />Console.WriteLine ("System Exception: " + Ex.Message );<br />Console.WriteLine ( "*** System Exception ***" );<br />Console.WriteLine();<br />}<br />}<br />Console.WriteLine();<br />Console.WriteLine();<br />Console.WriteLine("press any key to continue...");<br />Console.ReadLine();<br /><br />}<br />}<br /><br /><br />------------<br />Steve Schofield at 5/27/2002 1:55:42 PM<br /><br />Hi All,<br /><br />I'm trying to do 2 things with the .NET System.DirectoryServices namespace<br />and have hit a wall. I'm trying to 1. Recurse the metabase looking for all<br />top-level domains 2. While recursing the metabase determine if someone<br />has set the logfiledirectory variable within the particular domain, if not<br />it inherits from the root /LM/W3SVC logfiledirectory value.<br /><br />This has turned out to be more of a challenge that I expected and there<br />isn't any examples in the DOCS or on the web. I can go directly against<br />the metabase with this code snippet below to obtain the proeprty.<br />However trying to recurse the metabase is another challenge. There is a<br />code snippet below that was a vbscript file at one point that does recurses<br />but doesn't use System.DirectoryServices namespace. I tried bring back a<br />collection of the /LM/W3SVC which the .NET doc's say but its NULL.<br />However the server I was going after had 6 top-level domains. The biggest<br />challenge is trying to use the DirectoryEntry object to recurse, it seems to<br />be ok using traditional ADSI. Here is the code I've been working with,<br />appreciate any assistance someone has would be appreciated.<br /><br />Here is C# code that gets one property.<br />using System;<br />using System.DirectoryServices;<br />//our custom namespace<br />namespace myNamespace<br />{<br /><br /> //our custom class<br /> public class domain<br /> {<br /> public domain(string logpath)<br /> {<br /> logPath = logpath;<br /> }<br /><br /> //some member variables<br /> private string logPath;<br /> public string LogPath<br /> {<br /> get {return logPath;}<br /> set {logPath=value;}<br /> }<br /><br /> public string C(string domainName, string logPath)<br /> {<br /> string strPath = "IIS://TopLevelDomainName/" + logPath;<br /> System.DirectoryServices.DirectoryEntry ds = new DirectoryEntry(strPath);<br /> object s = ds.Properties["LogFileDirectory"].Value;<br /> return s.ToString();<br /> }<br />VB.NET winform I wrote with a button event to try recurse through the<br />metabase<br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As<br />System.EventArgs) Handles Button1.Click<br /> Dim entry As DirectoryEntry = New<br />DirectoryEntry("IIS://localhost/W3SVC/")<br /> RecurseObj(entry)<br /> End Sub<br /><br /><br /> Sub RecurseObj(ByVal IISObj)<br /> Dim oSubDir, fRecurse, oTemp<br /> 'On Error Resume Next<br /> fRecurse = False<br /> Select Case IISObj.Class<br /> Case "IIsWebFile"<br /> ' SetMappings(IISObj)<br /> Case "IIsWebServer", "IIsWebDirectory", "IIsWebVirtualDir",<br />"IIsWebService"<br /> SetMappings(IISObj)<br /> fRecurse = True<br /> End Select<br /><br /><br /> If fRecurse Then<br /> For Each oSubDir In IISObj<br /> RecurseObj(oSubDir)<br /> Next<br /> End If<br /> End Sub<br /><br /><br /> Sub SetMappings(ByVal IISObj)<br /> Dim entry As DirectoryEntry = New<br />DirectoryEntry("IIS://localhost/W3SVC/3")<br /> Console.Write(entry.Properties("ServerComment").Value & vbCrLf)<br /> End Sub }}<br /><br /><br /><br /><br /><br />
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > ADSI, .NET System.DirectoryServices Namespace and recursing the IIS metabase |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|