473,387 Members | 1,890 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.

Search active users from AD

1
Expand|Select|Wrap|Line Numbers
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Console.WriteLine("Select active users from AD:");
  6.             using (var context = new PrincipalContext(ContextType.Domain, "mydomain.com.nt", "OU=Departments,DC=com,DC=nt"))
  7.             {   
  8.                 DirectoryEntry ldapConnection = new DirectoryEntry("LDAP://mydomain.com.nt/OU=Departments,DC=or,DC=nt", @"User_name", "password", AuthenticationTypes.Delegation);
  9.                 DirectorySearcher search = new DirectorySearcher(ldapConnection);
  10.                 search.Filter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:= 2))";
  11.               search.PropertiesToLoad.Add("distinguishedName");
  12.                 search.PropertiesToLoad.Add("whenCreated");
  13.                 search.PropertiesToLoad.Add("description");
  14.                 search.PropertiesToLoad.Add("operatingSystem");
  15.                 search.PropertiesToLoad.Add("name");
  16.                 SearchResult result;
  17.                 List<Users> lstADUsers = new List<Users>();
  18.                 SearchResultCollection resultCol = search.FindAll();
  19.                 if (resultCol != null)
  20.                 {
  21.     for (int counter = 0; counter < resultCol.Count; counter++)
  22.                     {
  23.        string UserNameEmailString = string.Empty;
  24.                         result = resultCol[counter];
  25.                         if (result.Properties.Contains("samaccountname") &&
  26.                                  result.Properties.Contains("mail") &&
  27.                             result.Properties.Contains("displayname"))
  28.                         {
  29.         Users objSurveyUsers = new Users();
  30.             objSurveyUsers.Email = (String)result.Properties["mail"][0] +
  31.                               "^" + (String)result.Properties["displayname"][0];
  32.                             objSurveyUsers.UserName = (String)result.Properties["samaccountname"][0];
  33.                             objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];
  34.                             lstADUsers.Add(objSurveyUsers);
  35.                         }
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         public class Users
  41.         {
  42.             public string Email { get; set; }
  43.             public string UserName { get; set; }
  44.             public string DisplayName { get; set; }
  45.             public bool isMapped { get; set; }
  46.         }
  47.     }
  48. }
  49.  
Hi all! Help me, please with this task.
I try connect to remote AD from pc, witch is not in one domain with Active Directory. I do this in VS 2017. When I start this console app, here no exceptions or mistakes. But I don't get list of active users from AD.
Where is my mistake? Explain me, please.
Thanks
Jun 18 '17 #1
0 1278

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

Similar topics

1
by: Sajid | last post by:
Hi, I'm developing an online shopping cart. Usually the site administrator modifies products etc in the "Store". I want a mechanism for the administrator such that he should be able to view or...
2
by: kr | last post by:
I am trying to find a select on sysprocesses that would list all the active logins. An active login is a login that has a TSQL statment being executed on the server, This didnt work to well!...
4
by: tuarek | last post by:
Hi all, How can I list active users connected to database server in MS-DOS shell environment. Is there any specific CLP command for this? We are running DB2 ver 8.1.6. Thanks in advance. ...
3
by: Shane Suebsahakarn | last post by:
I have a rather odd problem that I'm at a loss to explain. The mdb is in A2K2 format, and has many tables linked to around 3-4 different back end mdbs. It is running on a Win2K3 server (set up as...
1
by: Arvind P Rangan | last post by:
Hi all, I am working on a project which checks for windows login and its rights and then opens up the rest of the forms according to the login and the rights already set in the windows. I...
5
by: Homer J. Simpson | last post by:
Hi, Any idea to get the -REAL- number of active users -WITHOUT- this kind of code ? ---------------------------------------------------------------------------- --------- Sub Session_OnStart...
6
by: timstu | last post by:
Hi all, thanks for your help in advance. I have a page that creates a .CSV file that has been migrated over to Windows Server 2003 from Windows 2000 Server. It worked fine before I moved it,...
1
by: Ven | last post by:
I need to display information a list of Active users on a web site. I can do the count using the global.asa but need to display individual information about each "active user" without writing it...
3
by: Naveen | last post by:
How can we keep track of how many active users are using the application.
5
by: Les Desser | last post by:
I know that the .ldb file should show the users currently logged into a database. However, when a user logs out I cannot detect any change in the file. I must be missing something as PSPad...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.