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_F or_Group(ADS_Pa th)
Dim Group_Informati on
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("D efaultNamingCon text")
ADS_Path = "CN=" & ADS_Path & ",OU=User
Groups,OU=Group s,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("D efaultNamingCon text")
ADS_Path = ADS_Path & ",OU=User Groups,OU=Group s,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_I nfo) Then
For Each Member in Group_Info.Memb ers
If LCase(Member.Cl ass) = "group" Then
Group_Name = Replace(Member. Name, "CN=", "")
Group_Informati on = Group_Informati on &
Get_ADS_Users_F or_Group(Group_ Name)
Else
Group_Informati on = Group_Informati on & Replace(Member. Name, "CN=",
"") & ","
End If
Next
End If
Get_ADS_Users_F or_Group = Group_Informati on
End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry( LDAP://CN=SOMEGROUP,OU =User
Groups,OU=Group s,OU=OU3,OU=OU4 ,DC=DC1,DC=DC2, DC=DC3")
Dim child As DirectoryEntry
For Each child In de.Children
Response.Write( child.Name.ToSt ring())
Next
Using this setup (which I've seen on numerous sites) does not display
anything...
Thanks for any help!
Chad 3 9874
try if the basic domain name is working
Dim de As DirectoryEntry = New DirectoryEntry( "LDAP://OU=Groups,DC=DC 1")
Dim child As DirectoryEntry
For Each child In de.Children
Response.Write( child.Name.ToSt ring())
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_F or_Group(ADS_Pa th) Dim Group_Informati on 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("D efaultNamingCon text") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Group s,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("D efaultNamingCon text") ADS_Path = ADS_Path & ",OU=User Groups,OU=Group s,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_I nfo) Then For Each Member in Group_Info.Memb ers If LCase(Member.Cl ass) = "group" Then Group_Name = Replace(Member. Name, "CN=", "") Group_Informati on = Group_Informati on & Get_ADS_Users_F or_Group(Group_ Name) Else Group_Informati on = Group_Informati on & Replace(Member. Name, "CN=", "") & "," End If Next End If Get_ADS_Users_F or_Group = Group_Informati on End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry( LDAP://CN=SOMEGROUP,OU =User Groups,OU=Group s,OU=OU3,OU=OU4 ,DC=DC1,DC=DC2, DC=DC3") Dim child As DirectoryEntry For Each child In de.Children Response.Write( child.Name.ToSt ring()) 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***@discussi ons.microsoft.c om> wrote in message
news:A7******** *************** ***********@mic rosoft.com... try if the basic domain name is working Dim de As DirectoryEntry = New DirectoryEntry( "LDAP://OU=Groups,DC=DC 1") Dim child As DirectoryEntry For Each child In de.Children Response.Write( child.Name.ToSt ring()) 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_F or_Group(ADS_Pa th) Dim Group_Informati on 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("D efaultNamingCon text") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Group s,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("D efaultNamingCon text") ADS_Path = ADS_Path & ",OU=User Groups,OU=Group s,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_I nfo) Then For Each Member in Group_Info.Memb ers If LCase(Member.Cl ass) = "group" Then Group_Name = Replace(Member. Name, "CN=", "") Group_Informati on = Group_Informati on & Get_ADS_Users_F or_Group(Group_ Name) Else Group_Informati on = Group_Informati on & Replace(Member. Name, "CN=", "") & "," End If Next End If Get_ADS_Users_F or_Group = Group_Informati on End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry( LDAP://CN=SOMEGROUP,OU =User Groups,OU=Group s,OU=OU3,OU=OU4 ,DC=DC1,DC=DC2, DC=DC3") Dim child As DirectoryEntry For Each child In de.Children Response.Write( child.Name.ToSt ring()) 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.Director yServices
Imports System.Web.Http Context
Imports System.Collecti ons
Imports ActiveDs
Public Class Query_ADS
Public Shared Function GetADS_Group_Me mbers(ByVal strGroup_Name As
String) As SortedList
Dim deGroup As DirectoryEntry
Dim MembersCollecti on As IADsMembers
Dim member As IADsUser
Dim objRootDSE As New DirectoryEntry( "LDAP://RootDSE")
Dim slGroupMembers As New SortedList
Try
deGroup = New DirectoryServic es.DirectoryEnt ry("LDAP://CN=" &
strGroup_Name & ",OU=User Groups,OU=Group s,OU=SOMEOU1,OU =SOMEOU2," &
objRootDSE.Prop erties("default NamingContext") (0).ToString())
MembersCollecti on = CType(deGroup.I nvoke("Members" ),
IADsMembers)
For Each member In MembersCollecti on
slGroupMembers. Add(member.Last Name, Replace(member. Name,
"CN=", "", , , CompareMethod.T ext) & "|;|" & member.ADsPath)
Next
Catch ex As Exception
Throw
Finally
If Not IsNothing(deGro up) Then deGroup.Close()
deGroup = Nothing
End Try
Return slGroupMembers
End Function
End Class
=============== =============== =============== =============== =======
"vinay" <vi***@discussi ons.microsoft.c om> wrote in message
news:A7******** *************** ***********@mic rosoft.com... try if the basic domain name is working Dim de As DirectoryEntry = New DirectoryEntry( "LDAP://OU=Groups,DC=DC 1") Dim child As DirectoryEntry For Each child In de.Children Response.Write( child.Name.ToSt ring()) 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_F or_Group(ADS_Pa th) Dim Group_Informati on 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("D efaultNamingCon text") ADS_Path = "CN=" & ADS_Path & ",OU=User Groups,OU=Group s,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("D efaultNamingCon text") ADS_Path = ADS_Path & ",OU=User Groups,OU=Group s,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_I nfo) Then For Each Member in Group_Info.Memb ers If LCase(Member.Cl ass) = "group" Then Group_Name = Replace(Member. Name, "CN=", "") Group_Informati on = Group_Informati on & Get_ADS_Users_F or_Group(Group_ Name) Else Group_Informati on = Group_Informati on & Replace(Member. Name, "CN=", "") & "," End If Next End If Get_ADS_Users_F or_Group = Group_Informati on End Function
..NET Code:
Dim de As DirectoryEntry = New DirectoryEntry( LDAP://CN=SOMEGROUP,OU =User Groups,OU=Group s,OU=OU3,OU=OU4 ,DC=DC1,DC=DC2, DC=DC3") Dim child As DirectoryEntry For Each child In de.Children Response.Write( child.Name.ToSt ring()) 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
instanciate SearchResultCollection Class.
more clearly, a SearchResult object is created, at the inside of FindAll()
method, then how can I put this object into the SearchResultCollection
object. there is any method releated to input operation.
|
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} belongs:"+ oUser.Name);
The oUser object is returning an error " AdsObject <error: an exception of
type: {System.Runtime.InteropServices.COMException} occurred>
System.DirectoryServices.Interop.UnsafeNativeMethods.IAds
"
|
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 directory. I'll log into the app
twice with the same account and sometimes it works, while with others I get
the following:
System.Runtime.InteropServices.COMException (0x80072020): An operations
error occurred at...
|
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)
The code below returns all of the keys (I assume) but I can't figure out how
to extract the values associated with them:
Here is the code I'm using:
| |
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, having been advised by
several luminaries that that is a "good thing to do"... :-)
However, I'm experiencing a problem with the IEnumerable interface. (N.B. I
understand fully that I should be using the LDAP provider instead of the
WinNT provider...
|
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. (Exception from HRESULT: 0x8007202F)"
My code is like this:
<code>
|
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 connection is active or
not if I can create a DirectoryEntry with whatever data I want since the
data really isn't verified until I try to use it? I am not able to
determine whether the connection is really going to be available until
the Try {}...
|
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 on the other domain.
Other functions work on the other domain like get all the users and get all
the groups and I can validate users on the other domain so I think I am
communciating with the other domain OK just not with the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |