Developping for the translation industry RSS 2.0



 Friday, 20 March 2009

This function creates a new user Account in your active directory domain:

public string CreateUserAccount(string ldapPath, string userName, string password)
{
    try
    {
        string connectionPrefix = "LDAP://" + ldapPath;

        DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
        DirectoryEntry newUser = dirEntry.Children.Add(
"CN=" + userName, "user");

        newUser.Properties["samAccountName"].Value = userName;
        newUser.CommitChanges();

        newUser.Invoke("SetPassword", new object[] { password });
        newUser.CommitChanges();

        dirEntry.Close();
        newUser.Close();
    }
    catch (System.DirectoryServices.DirectoryServicesCOMException E)
    {
        //…
    }
}
 

Related posts :

How To: Use Active Directory To Authenticate Users

How To: set NTFS Permissions using C#

How to enumerate the Domain Controllers in the current Domain in C#

Friday, 20 March 2009 13:11:31 (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C# | Code Snippet

Navigation
Advertisement
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Stanislas Biron
Sign In
Statistics
Total Posts: 135
This Year: 0
This Month: 0
This Week: 0
Comments: 1
All Content © 2017, Stanislas Biron