I am starting to translate some code from ASP to ASP.NET (VB). I was able
to query ADS to get a users groups that they belong to, and also query a
group and get a list of users. However, I can't seem to get this to work in
VB.Net. Here's what I have:
OLD ASP Code:
Function Get_ADS_Users_For_Group(ADS_Path)
Dim Group_Information
Dim Error_Number
On Error Resume Next
Get_ADS_Object_Counter = 0
Error_Number = 99 'Generic Error number, no actual value
Do While Error_Number <> 0 AND Get_ADS_Object_Counter < 10
If InStr(ADS_Path, "CN=") = 0 Then
Set ADS_Root = GetObject("LDAP://RootDSE")
ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext")
ADS_Path = "CN=" & ADS_Path & ",OU=User
Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path
End If
If InStr(ADS_Path, "OU=") = 0 Then
Set ADS_Root = GetObject("LDAP://RootDSE")
ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext")
ADS_Path = ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," &
ADS_Domain_Path
End If
'Response.Write ADS_Path
'Response.End
Set ADS_Object = GetObject("LDAP://" & ADS_Path)
Error_Number = Err.Number
If Error_Number <> 0 Then
Get_ADS_Object_Counter = Get_ADS_Object_Counter + 1
If Get_ADS_Object_Counter = 9 Then
Exit Do
End If
Pause(2)
End If
Loop
Set Group_Info = ADS_Object
On Error GoTo 0
If NOT IsEmpty(Group_Info) Then
For Each Member in Group_Info.Members
If LCase(Member.Class) = "group" Then
Group_Name = Replace(Member.Name, "CN=", "")
Group_Information = Group_Information &
Get_ADS_Users_For_Group(Group_Name)
Else
Group_Information = Group_Information & Replace(Member.Name, "CN=",
"") & ","
End If
Next
End If
Get_ADS_Users_For_Group = Group_Information
End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry(LDAP://CN=SOMEGROUP,OU=User
Groups,OU=Groups,OU=OU3,OU=OU4,DC=DC1,DC=DC2,DC=DC 3")
Dim child As DirectoryEntry
For Each child In de.Children
Response.Write(child.Name.ToString())
Next
Using this setup (which I've seen on numerous sites) does not display
anything...
Thanks for any help!
Chad 3 9861
try if the basic domain name is working
Dim de As DirectoryEntry = New DirectoryEntry("LDAP://OU=Groups,DC=DC1")
Dim child As DirectoryEntry
For Each child In de.Children
Response.Write(child.Name.ToString())
Next
what i use for LDAP is example - localhost:389 OR servername is optional
"LDAP://localhost:389/DC=Yahoo,DC=com"
-- http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
"Chad Beckner" wrote: I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't seem to get this to work in VB.Net. Here's what I have:
OLD ASP Code:
Function Get_ADS_Users_For_Group(ADS_Path) Dim Group_Information Dim Error_Number On Error Resume Next Get_ADS_Object_Counter = 0 Error_Number = 99 'Generic Error number, no actual value Do While Error_Number <> 0 AND Get_ADS_Object_Counter < 10 If InStr(ADS_Path, "CN=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If If InStr(ADS_Path, "OU=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If
'Response.Write ADS_Path 'Response.End
Set ADS_Object = GetObject("LDAP://" & ADS_Path) Error_Number = Err.Number If Error_Number <> 0 Then Get_ADS_Object_Counter = Get_ADS_Object_Counter + 1 If Get_ADS_Object_Counter = 9 Then Exit Do End If Pause(2) End If Loop Set Group_Info = ADS_Object On Error GoTo 0 If NOT IsEmpty(Group_Info) Then For Each Member in Group_Info.Members If LCase(Member.Class) = "group" Then Group_Name = Replace(Member.Name, "CN=", "") Group_Information = Group_Information & Get_ADS_Users_For_Group(Group_Name) Else Group_Information = Group_Information & Replace(Member.Name, "CN=", "") & "," End If Next End If Get_ADS_Users_For_Group = Group_Information End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry(LDAP://CN=SOMEGROUP,OU=User Groups,OU=Groups,OU=OU3,OU=OU4,DC=DC1,DC=DC2,DC=DC 3") Dim child As DirectoryEntry For Each child In de.Children Response.Write(child.Name.ToString()) Next
Using this setup (which I've seen on numerous sites) does not display anything...
Thanks for any help!
Chad
That would be if I want the entire tree, which I don't. I just want the
users of "that" group... Also, I have tried code like this, but it doesn't
return any results....
Chad
"vinay" <vi***@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com... try if the basic domain name is working Dim de As DirectoryEntry = New DirectoryEntry("LDAP://OU=Groups,DC=DC1") Dim child As DirectoryEntry For Each child In de.Children Response.Write(child.Name.ToString()) Next
what i use for LDAP is example - localhost:389 OR servername is optional "LDAP://localhost:389/DC=Yahoo,DC=com" -- http://pathidotnet.blogspot.com ===== vInAypAtHi o__ ---_,>/'_------ (_) \(_) ---------------
"Chad Beckner" wrote:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't seem to get this to work in VB.Net. Here's what I have:
OLD ASP Code:
Function Get_ADS_Users_For_Group(ADS_Path) Dim Group_Information Dim Error_Number On Error Resume Next Get_ADS_Object_Counter = 0 Error_Number = 99 'Generic Error number, no actual value Do While Error_Number <> 0 AND Get_ADS_Object_Counter < 10 If InStr(ADS_Path, "CN=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If If InStr(ADS_Path, "OU=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If
'Response.Write ADS_Path 'Response.End
Set ADS_Object = GetObject("LDAP://" & ADS_Path) Error_Number = Err.Number If Error_Number <> 0 Then Get_ADS_Object_Counter = Get_ADS_Object_Counter + 1 If Get_ADS_Object_Counter = 9 Then Exit Do End If Pause(2) End If Loop Set Group_Info = ADS_Object On Error GoTo 0 If NOT IsEmpty(Group_Info) Then For Each Member in Group_Info.Members If LCase(Member.Class) = "group" Then Group_Name = Replace(Member.Name, "CN=", "") Group_Information = Group_Information & Get_ADS_Users_For_Group(Group_Name) Else Group_Information = Group_Information & Replace(Member.Name, "CN=", "") & "," End If Next End If Get_ADS_Users_For_Group = Group_Information End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry(LDAP://CN=SOMEGROUP,OU=User Groups,OU=Groups,OU=OU3,OU=OU4,DC=DC1,DC=DC2,DC=DC 3") Dim child As DirectoryEntry For Each child In de.Children Response.Write(child.Name.ToString()) Next
Using this setup (which I've seen on numerous sites) does not display anything...
Thanks for any help!
Chad
Here is what I have so far... It works, but there has got to be a better way
to do this, without using ActiveDS, etc. I would love to use the
de.Children setup...
================================================== =================
Option Explicit On
Option Strict On
Imports System
Imports System.DirectoryServices
Imports System.Web.HttpContext
Imports System.Collections
Imports ActiveDs
Public Class Query_ADS
Public Shared Function GetADS_Group_Members(ByVal strGroup_Name As
String) As SortedList
Dim deGroup As DirectoryEntry
Dim MembersCollection As IADsMembers
Dim member As IADsUser
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim slGroupMembers As New SortedList
Try
deGroup = New DirectoryServices.DirectoryEntry("LDAP://CN=" &
strGroup_Name & ",OU=User Groups,OU=Groups,OU=SOMEOU1,OU=SOMEOU2," &
objRootDSE.Properties("defaultNamingContext")(0).T oString())
MembersCollection = CType(deGroup.Invoke("Members"),
IADsMembers)
For Each member In MembersCollection
slGroupMembers.Add(member.LastName, Replace(member.Name,
"CN=", "", , , CompareMethod.Text) & "|;|" & member.ADsPath)
Next
Catch ex As Exception
Throw
Finally
If Not IsNothing(deGroup) Then deGroup.Close()
deGroup = Nothing
End Try
Return slGroupMembers
End Function
End Class
================================================== =================
"vinay" <vi***@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com... try if the basic domain name is working Dim de As DirectoryEntry = New DirectoryEntry("LDAP://OU=Groups,DC=DC1") Dim child As DirectoryEntry For Each child In de.Children Response.Write(child.Name.ToString()) Next
what i use for LDAP is example - localhost:389 OR servername is optional "LDAP://localhost:389/DC=Yahoo,DC=com" -- http://pathidotnet.blogspot.com ===== vInAypAtHi o__ ---_,>/'_------ (_) \(_) ---------------
"Chad Beckner" wrote:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't seem to get this to work in VB.Net. Here's what I have:
OLD ASP Code:
Function Get_ADS_Users_For_Group(ADS_Path) Dim Group_Information Dim Error_Number On Error Resume Next Get_ADS_Object_Counter = 0 Error_Number = 99 'Generic Error number, no actual value Do While Error_Number <> 0 AND Get_ADS_Object_Counter < 10 If InStr(ADS_Path, "CN=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If If InStr(ADS_Path, "OU=") = 0 Then Set ADS_Root = GetObject("LDAP://RootDSE") ADS_Domain_Path = ADS_Root.Get("DefaultNamingContext") ADS_Path = ADS_Path & ",OU=User Groups,OU=Groups,OU=OU3,OU=OU4," & ADS_Domain_Path End If
'Response.Write ADS_Path 'Response.End
Set ADS_Object = GetObject("LDAP://" & ADS_Path) Error_Number = Err.Number If Error_Number <> 0 Then Get_ADS_Object_Counter = Get_ADS_Object_Counter + 1 If Get_ADS_Object_Counter = 9 Then Exit Do End If Pause(2) End If Loop Set Group_Info = ADS_Object On Error GoTo 0 If NOT IsEmpty(Group_Info) Then For Each Member in Group_Info.Members If LCase(Member.Class) = "group" Then Group_Name = Replace(Member.Name, "CN=", "") Group_Information = Group_Information & Get_ADS_Users_For_Group(Group_Name) Else Group_Information = Group_Information & Replace(Member.Name, "CN=", "") & "," End If Next End If Get_ADS_Users_For_Group = Group_Information End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry(LDAP://CN=SOMEGROUP,OU=User Groups,OU=Groups,OU=OU3,OU=OU4,DC=DC1,DC=DC2,DC=DC 3") Dim child As DirectoryEntry For Each child In de.Children Response.Write(child.Name.ToString()) Next
Using this setup (which I've seen on numerous sites) does not display anything...
Thanks for any help!
Chad This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: hykim |
last post by:
Hello, everyone.
according to MSDN, there is any constructor of
System.DirectoryServices.SearchResultCollection Class.
if I implement DirectorySearcher.FindAll() method by myself, then how can I...
|
by: Fabrizio |
last post by:
(Sorry for the crosspost, but I really don't know which is the right
newsgroup!)
Hi all,
I try to change the password to a user that as to change the password at
first logon:
try
{
|
by: news.microsoft.com |
last post by:
Hi,
Anyone there who can give me a jump start for retrieving the groups a user
belongs to???
Since now i tried this but keeps on giving an error on line
(listBox1.Items.Add("Groups to which {0}...
|
by: Chris Frohlich |
last post by:
All,
I've built an Employee Directory with ASP.NET app that queries Active
Directory for users and builds links with the results. What I'm seeing is
really intermittent failures to bind to the...
|
by: RSH |
last post by:
I am using System.DirectoryServices to query our AD in order to get
information about users.
I am having problems understanding how to get at the Username and the Email
address (to begin with)
...
|
by: Mark Rae |
last post by:
Hi,
I'm in the process of updating an ASP.NET v1.1 web app to v2. The app uses
ActiveDirectory a great deal, and I'm trying to use the new
System.Collections.Generic namespace where possible,...
|
by: Peter Bradley |
last post by:
I'm trying to use System.DirectoryServices to update Active Directory from a
Web Service. When I try to commit the changes, I get the following error
message:
"A constraint violation occurred....
|
by: Brandon McCombs |
last post by:
Hello,
From my understanding, DirectoryEntry is used to connect to Active
Directory. Although this makes no sense whatsoever I accept it. The
problem is how am I supposed to test whether a...
|
by: =?Utf-8?B?SmVycnkgQw==?= |
last post by:
I am using this code to get groups for a user and getting a error (5) on the
GetAuthorizationGroups() function .
There are two domains.
This function works on the local domain but does not work...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |