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 9856
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |