473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trying to get Users in a Group

Hello,

I am trying to retrieve the list of users that belong to a security group Active Directory. But I
am unable to retrieve the users. Below you will find the code that I am using, please note that the
LDAP string is pointing to a Security Group that has about 6 users in it.

DirectoryEntry entry = new
DirectoryEntry("LDAP://win2k3domain.net/CN=ExternalUsers,OU=KB_Users,DC=win2k3domain,DC=ne t");

foreach(DirectoryEntry child in entry.Children)
{
Console.WriteLine("Name: {0}", child.Name); //not retrieving anything
}

Am I missing something, or is there a better way to search for and retrieve users from a group?
Nov 17 '05 #1
2 7231
"Ed_P." <ed**@no-email.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Am I missing something, or is there a better way to search for and
retrieve users from a group?


Not necessarily better...

using System;
using System.Collections;
using System.DirectoryServices;

public static Hashtable GetUsersInGroup(string pstrDomain, string pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objGroup = null;
object objMembers = null;
Hashtable htblUsers = new Hashtable();

try
{
objADEntry = new DirectoryEntry("WinNT://" + pstrDomain + ",
domain");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
objMembers = objGroup.Invoke("Members");
foreach (object objMember in (IEnumerable)objMembers)
{
DirectoryEntry objUser = new DirectoryEntry(objMember);
htblUsers.Add(objUser.Name, GetObjectProperty(objUser.Name,
"FullName"));
}
return htblUsers;
}
catch (Exception)
{
throw;
}
}
Nov 17 '05 #2

"Ed_P." <ed**@no-email.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am trying to retrieve the list of users that belong to a security group
Active Directory. But I am unable to retrieve the users. Below you will
find the code that I am using, please note that the LDAP string is
pointing to a Security Group that has about 6 users in it.

DirectoryEntry entry = new
DirectoryEntry("LDAP://win2k3domain.net/CN=ExternalUsers,OU=KB_Users,DC=win2k3domain,DC=ne t");

foreach(DirectoryEntry child in entry.Children)
{
Console.WriteLine("Name: {0}", child.Name); //not retrieving anything
}

Am I missing something, or is there a better way to search for and
retrieve users from a group?


Children returns DirectoryEntries, these can contain other groups as well,
so you'll have to filter the resultset. Also you might not need all
properties associated with an entry, so you'll better use a DirectorySeacher
so you can specify the properties you need.
Following is a small sample that illustrates how you can specify the
properties you need, the number of entries per page for a pages search and
the scope level of the search...

using(DirectoryEntry entry = new DirectoryEntry(LDAP://...........)
{
using(DirectorySearcher src = new DirectorySearcher())
{
string[] props = {"sn", "givenname", "sAMAccountName",
"userAccountControl"};
src.PropertiesToLoad.AddRange(props);
src.SearchRoot = ent;
src.SearchScope = SearchScope.OneLevel;
src.Filter = "(objectCategory=user)";
src.PageSize = 500; // In pages of 500 entries
SearchResultCollection res = src.FindAll();
foreach(SearchResult sc in res)
{
foreach(string myKey in res.PropertiesLoaded)
{
Console.Write(myKey + " = ");
foreach( Object myCollection in sc.Properties[myKey])
{
Console.WriteLine(myCollection);
}
}
}
}
}

Willy.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Betty Harvey | last post by:
The next meeting of the XML Users Group will be held on Wednesday, August 20, 2003 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting...
0
by: Betty Harvey | last post by:
The next meeting of the XML Users Group will be held on Wednesday, September 17, 2003 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting...
1
by: intl04 | last post by:
I am getting strange print-related error messages when trying to create (not print!) reports. For example, when I click 'new' to create a report then choose 'design view', I get an error message...
1
by: Access | last post by:
Here is my function to change a users permission level in the database. This relates to an Access database secured using Access security. This function is called if the end user changes a staff...
1
by: Rod | last post by:
We've implemented forms authentication with Active Directory. We're slowly working on converting our Crystal Reports' reports from a VB6 application into Crystal Reports for .NET in our ASP.NET...
7
by: John Blair | last post by:
Hi, I am trying to get the datacache1 sample working on my PC. I have downloaded the MSDE 2000 sample SQL Server database and the pubs sample database and installed it. I can view the contents...
3
by: Igor Kryltsov | last post by:
Hi,I am using slightly modified example posted by Doug Younger and answered by Tom Lane :)(http://archives.postgresql.org/pgsql-sql/1999-08/msg00159.php) I have the following 2 tables: Table...
6
by: google | last post by:
I have a few general questions. I am working on a new database to be used within my company. I would like to give a couple of people, particularly HR, the ability to add and delete Access users,...
6
by: Jan | last post by:
Hi: I have created a secured database for a client. For various reasons, I don't want the client to have full persmissions for the database; they aren't in the admins group. I have instead tried...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
jinu1996
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.