Home

C#

Vb.Net

Java

Sharepoint

Php

Action Script









Downloads
Technology News
Templates
Web Hosting
Articles
Games
Blogger
Google





Wednesday, September 24, 2008
Active Directory Utility Class
Active Directory Utility Class

This static class contains utility methods which are useful as samples of how to access Active Directory information from a .NET application.

Note that this class is NOT production-ready; it is for sample use only! A production-ready application would:

• Store the credentials used to access AD in a secure location (username and password are embedded in the code which is a big security hole!)
• Consider using appropriate “least privilege” account(s)
• Have better exception handling

Furthermore, this sample class assumes that all users and groups are in the same Active Directory domain; modifications will be required to handle multiple (trusted) domains.

The class provides the following. Note that all user and group names are not qualified by their domain name in this version.

GetUserCN (username) – Returns the common name (first and list names) of a user given the username

GetUserInfo (username) – Returns a UserInfo structure (defined in the same .cs file) containing the first name, last name and login name for the user

GetUserInfoEx (username) – Returns a UserInfoEx structure (defined in the same .cs file) containing the user’s first and last name, address, phone number, email and other information

UpdateUserProperty (username, propertyName, propertyValue) – Updates a single property of an AD user

GetAdGroups (prefix) – Return a string array of Active Directory group names beginning with the specified prefix

GetGroupsForUser (username) – Return a string array of Active Directory group names which the specified user is a member of

FindUsers (username) – Return a UserInfo array of users matching the specified pattern

AddUserToGroup (username, groupname) – Adds the specified user to the specified group

RemoveUserFromGroup (username, groupname) – Removes the specified user from the specified group

AddNewUser (username, password, firstName, lastName, description) – Creates a new user with the specified information)

ChangeUserPassword (username, newPassword) – Changes a user’s password to a new value.

Download

Labels:

1 Comments:

great code. Your code solves my problem. Thanks.

September 25, 2008 at 5:50 AM  

Post a Comment

<< Home