Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,216 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,111 people online right now. Registration is fast and FREE... Join Now!




Active Directory Default Naming Context

 
Reply to this topicStart new topic

Active Directory Default Naming Context

Mr Ed
17 Nov, 2007 - 02:38 PM
Post #1

New D.I.C Head
*

Joined: 9 Nov, 2007
Posts: 14


My Contributions
I am trying to obtain the default naming context in the most efficient way possible short of hard coding it :-)


This is from the Active Directory Cookbook and of course works as expected

CODE

Sub Main()
    Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
    Dim strAttrName As String
    Dim objValue As Object
    For Each strAttrName In objRootDSE.Properties.PropertyNames
        For Each objValue In objRootDSE.Properties(strAttrName)
            Console.WriteLine(strAttrName & " : " & objValue.ToString)
        Next objValue
    Next strAttrName
End Sub


It prints amongst other things:
...
defaultNamingContext : DC=Corp,DC=com
...

Since at this time I am only interested the defaultNamingContext value I tried

CODE

Sub Main()
    Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
    Dim strAttrName As String
    Dim objValue As Object
    strAttrName = "defaultNamingContext"
    objValue = objRootDSE.Properties(strAttrName)
    console.writeline(objValue.ToStrint)
End Sub


Which printed
System.DirectoryServices.PropertyValueCollection

I do not understand why is it printing what it is instead of it's value

Mr Ed
User is offlineProfile CardPM
+Quote Post

scotbrymac
RE: Active Directory Default Naming Context
22 Nov, 2007 - 02:53 PM
Post #2

New D.I.C Head
*

Joined: 22 Nov, 2007
Posts: 1


My Contributions
Try the bellow this is abit of vb script but should work just the same in .net, works fine for me with several scripts I use. you might need to test if using in .net

CODE
Set rootDSE = GetObject("LDAP://RootDSE")
domainContainer = rootDSE.Get("defaultNamingContext")
Set conn = CreateObject("ADODB.Connection")
conn.provider = "ADSDSOObject"
conn.Open "ADs Provider"

User is offlineProfile CardPM
+Quote Post

TheChuck
RE: Active Directory Default Naming Context
17 Dec, 2007 - 01:15 PM
Post #3

New D.I.C Head
*

Joined: 17 Dec, 2007
Posts: 1


My Contributions
Mr. Ed,
Here's what I figured out to get the Nameing Context:
CODE
oRootDSE.Properties.Item("defaultNamingContext").Value

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:27AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month