473,732 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting users from a specifc AD group

I want to get a list of users from a specific AD group. I use this
code:

*************** *************** *************** *************** *************** *************
SearchResult result;
DirectorySearch er search = new DirectorySearch er();
search.Filter = String.Format(" (cn={0})", groupName);
search.Properti esToLoad.Add("m ember");
result = search.FindOne( );

ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properti es["member"].Count; counter++)
{
string user = (string)result. Properties["member"][counter];
userNames.Add(u ser);
}
}

*************** *************** *************** *************** *************** *************
When the code is finished user string = "CN=Egholm Jacob (DFDS
A/S),OU=Developme nt,OU=IT,OU=DFD S AS,DC=dk,DC=dfd s,DC=root"

But what I want to do is getting information like givenName,
displayName etc. from the user.
What shall I do?

Jan 4 '06 #1
5 9621
You should load the givenName and displayName property from the AD.

string[] props = {"givenName ", "displayNam e", ".."};
search.Properti esToLoad.AddRan ge(props);
....

Willy.

<eg****@gmail.c om> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I want to get a list of users from a specific AD group. I use this
code:

*************** *************** *************** *************** *************** *************
SearchResult result;
DirectorySearch er search = new DirectorySearch er();
search.Filter = String.Format(" (cn={0})", groupName);
search.Properti esToLoad.Add("m ember");
result = search.FindOne( );

ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properti es["member"].Count; counter++)
{
string user = (string)result. Properties["member"][counter];
userNames.Add(u ser);
}
}

*************** *************** *************** *************** *************** *************
When the code is finished user string = "CN=Egholm Jacob (DFDS
A/S),OU=Developme nt,OU=IT,OU=DFD S AS,DC=dk,DC=dfd s,DC=root"

But what I want to do is getting information like givenName,
displayName etc. from the user.
What shall I do?

Jan 4 '06 #2
Thanks for your reply. I have change my code to this:

*************** *************** *************** *************** *************** **************

SearchResult result;
DirectorySearch er search = new DirectorySearch er();
search.Filter = String.Format(" (cn={0})", groupName);
search.Properti esToLoad.Add("m ember");
search.Properti esToLoad.Add("d isplayName");
result = search.FindOne( );
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properti es["member"].Count; counter++)
{
string user = (string)result. Properties["member"][counter];

string test =
(string)result. Properties["displayNam e"][counter];
userNames.Add(u ser);
}
}
*************** *************** *************** *************** *************** **************
The string variable test returns the name of the group and not the name
of the user in the group.

Jan 4 '06 #3


<eg****@gmail.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Thanks for your reply. I have change my code to this:

*************** *************** *************** *************** *************** **************

SearchResult result;
DirectorySearch er search = new DirectorySearch er();
search.Filter = String.Format(" (cn={0})", groupName);
search.Properti esToLoad.Add("m ember");
search.Properti esToLoad.Add("d isplayName");
result = search.FindOne( );
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properti es["member"].Count; counter++)
{
string user = (string)result. Properties["member"][counter];

string test =
(string)result. Properties["displayNam e"][counter];
userNames.Add(u ser);
}
}
*************** *************** *************** *************** *************** **************
The string variable test returns the name of the group and not the name
of the user in the group.

If your cn denotes a "username", you should apply the following filter.

src.Filter = "(objectCategor y=user)";

also, you should not use a for loop to iterate, use foreach instead.
Willy.
Jan 4 '06 #4
Hello Willy

I have change my code (look below), but it still dosen't work.

*************** *************** *************** *************** *************** **************
DirectoryEntry searchRoot = new DirectoryEntry( @"LDAP://dfds.root");
DirectorySearch er search = new DirectorySearch er(searchRoot);
search.Filter = "(&(cn=Grou p CFS Handlers)(objec tCategory=user) )";
search.Properti esToLoad.Add("s amaccountname") ;

foreach (SearchResult res in search.FindAll( ))
{
string dummy = res.Properties["samaccountname "].ToString();
}
*************** *************** *************** *************** *************** **************

I want to list all the users in the group "Group CFS Handlers", but
search.FindAll( ) returns 0 results. I just checked the AD and the group
"Group CFS Handlers" contain one user.
I you have any idea what I do wrong, please let my know. I believe it
has something to do with my filter, but I don't know what.

Jan 5 '06 #5
Hello Willy

I have change my code (look below), but it still dosen't work.

*************** *************** *************** *************** *************** **************
DirectoryEntry searchRoot = new DirectoryEntry( @"LDAP://dfds.root");
DirectorySearch er search = new DirectorySearch er(searchRoot);
search.Filter = "(&(cn=Grou p CFS Handlers)(objec tCategory=user) )";
search.Properti esToLoad.Add("s amaccountname") ;

foreach (SearchResult res in search.FindAll( ))
{
string dummy = res.Properties["samaccountname "].ToString();
}
*************** *************** *************** *************** *************** **************

I want to list all the users in the group "Group CFS Handlers", but
search.FindAll( ) returns 0 results. I just checked the AD and the group
"Group CFS Handlers" contain one user.
I you have any idea what I do wrong, please let my know. I believe it
has something to do with my filter, but I don't know what.

Jan 5 '06 #6

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

Similar topics

1
1968
by: scott289 | last post by:
Getting the lists of users in a given Domain Group? For example, our Network people have created a group called MyAppUsers, and have added certain Users to this group. I need to get a list of these users by pasing in the name of the Group. Is that possible?
3
2253
by: BobTheDatabaseBoy | last post by:
.... got: win2K, v8.1.6 login to win2K is to the network: user; bob13, domain; foo it's a win2K domain. i then login to my local db as db2admin. LIST APPLICATIONS fails with security error. tells me bob13 doesn't have the rights. bob13 has all rights in CC user maintenance. bob13 is member of Administrators in win2K on the box. i'm not logged in to DB2 as bob13, just the box(? domain).
5
8139
by: Mike Turco | last post by:
(This was also posted to comp.database.ms-access before I realized this was the hep group.) Lets say that my WinXP computer has two users: Michael and Kathryn. One or the other logs into the computer and opens up an Access database (I happen to be using 2002). There is no security on the database -- just click on the shortcut and you're in. I want to be able to determine who opened that database by knowing who logged into the computer.
8
10013
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/WebApplication1'. 'HTTP/1.1 500 Internal Server Error'."
11
4859
by: Derek Martin | last post by:
Using VB.Net, I would like to retrieve the currently logged in user's DN from Active Directory. Alternatively, if, using WindowsIdentity, or something similar, I would like to get the user's full name that is found on the Workstation Locked screen between the ( )'s. Does anyone know how to do that? The only constraint: no use of ActiveDS.dll permitted by the design. Many thanks! Derek
4
4859
by: wqyuwss | last post by:
Hi, We have several core dumps in our product. These core dump can be reproduced in the same place. That is system function call std::basic_istream<char,std::char_traits<char>>::getline. The result of pstack for the core dump is > pstack core | c++filt
1
1290
by: Mike Spike | last post by:
HI all, How do I go about getting the permmisions of a file. I have been able to get a list of access control rules and tell if they are restricting or permiting a permmision but I cant tell which role / right they are refering to: I can get this type information by using the fileSystemSecurity object and pointing it to a file or folder:
4
5689
by: shashank kadge | last post by:
hi all, i am trying to get local admin users and groups on a windows server. here is the C# code that i am using *************************************************************************************************** DirectoryEntry AD = new DirectoryEntry("WinNT://" + sServerName + ",Computer",UserName,Password); DirectoryEntry admGroup = AD.Children.Find("Administrators", "Group"); object members = admGroup.Invoke("Members", null); ...
5
13208
by: Michael Howes | last post by:
I'm writing a utility to manage a machines *local* accounts in c# I am getting all the users in a specific Group just fine but when I want to get some of the information on each user from their Properties collection I can't get the properties on some users. For example, I get all the users that are part of my machines Administrators Group. I get get the properties of the built in local Administrator account and some local IT account,...
0
8944
marktang
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...
0
9445
Oralloy
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...
1
9234
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,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
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...
1
6733
isladogs
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...
0
6030
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();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.