473,387 Members | 1,512 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,387 software developers and data experts.

getting all users in a windows domain

Ok currently i am working in an environment with 20 computers all in the domain, which has about 40 users. These 40 users change often. I need to write an application that pulls all the usernames and if possible more information(i.e. There first and last name etc...) from the domain server. I am an administrator so i have full access to this server and can get to all the information manually through active directory on Windows Server 2003, but i found it redundant to have to type the information twice(i.e. once in active directory and again in the system i am tweaking). I have been researching the new classes for domains in the .net framework 2 and have come up blank any help would be great.

~xxsodapopxx5
Apr 25 '07 #1
4 1251
I have started finding some things about this.


i have found the code to get the current user on the domain.

Expand|Select|Wrap|Line Numbers
  1. my.User.Name
i still need help on getting a collection of all of the users on the domain
Apr 26 '07 #2
radcaesar
759 Expert 512MB
For this you have to query the active directory.

The Assembly is System.Directory Services.

Here Is for you,

//namespace required
using System.DirectoryServices;

//creating an instance of DirectoryEntry pointing to the //“TestOU” with valid credentials.
DirectoryEntry DE = new DirectoryEntry(@"LDAP://Norchio/OU=TestOU,DC=norchio,DC=com","Username","password" ,AuthenticationTypes.ServerBind | AuthenticationTypes.Secure);

// creating an instance of DirectorySearcher which will search in AD.
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(DE);

//setting up the search filters like if we want users from OU in AD
mySearcher.Filter = ("(objectClass=user)");
Console.WriteLine("Users Listing from Active Directory");

foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
ResultPropertyCollection RCol = resEnt.Properties;
foreach(string myKey in RCol.PropertyNames)
{
string tab = " ";
if (myKey == "samaccountname")
{
Console.WriteLine(myKey + " ");
foreach(object myCollection in RCol[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
}
}
Console.ReadLine();
Apr 26 '07 #3
I am very greatful for your help, this is much appreciated... although there is something that i am not understanding. I Primarily program in vb.net 2005 so this code is somewhat foreign. I can interpret most of the code but can you explaing this line?

Expand|Select|Wrap|Line Numbers
  1. //creating an instance of DirectoryEntry pointing to the //“TestOU” with valid credentials.
  2. DirectoryEntry DE = new DirectoryEntry(@"LDAP://Norchio/OU=TestOU,DC=norchio,DC=com","Username","password",AuthenticationTypes.ServerBind | AuthenticationTypes.Secure);
i do not understand what the first 3 parameters after the @

what path am i supposed to enter?
Apr 27 '07 #4
bump. bump. bump.
May 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark | last post by:
hey, i'm trying to get the current windows user and the groups they are in. Intergrated windows auth on and annoymous access turned off on IIS. However when trying to compile the following code...
8
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...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
11
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...
2
by: Scott M. Lyon | last post by:
I'm having some strange problems with a VB.NET application that I support. The application currently uses SystemInformation.UserName() and SystemInformation.UserDomainName() to determine who is...
6
by: Mr Newbie | last post by:
Hi, Im in a situation where I need to restrict users, but I dont have access or wont be allowed access to manage groups in the domain. How can I restrict access is this case ? -- Best...
4
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...
5
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...
1
by: Jack Black | last post by:
Is there a trick (or is it even possible) to get an xcopy distribution of an app to work on restricted-privilege domain users' workstations? I have the appropriate application properties set in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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,...
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...

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.