.net-2.0ldapadsiuser-administration

What is a good .Net library for Windows User Administration?


We have a company intranet with staff management functions. I would like to begin automating setup of new staff members, e.g. creating Windows accounts for them, creating their home folders, setting up shares, and the like. When a staff member leaves the company I would like to automatically remove their user.

I have been battling to find any good references or libraries for administering users using .Net 2.0.

I am willing to write ADSI code or even WMI code, but need some sample code to kick start the process.


Solution

  • I discovered the following sample on the Code Project, showing how to add a new user using DirectoryServices:

    private void AddUser(string strDoamin, string strLogin, string strPwd)
    {
      DirectoryEntry obDirEntry = null;
      try
      {
        obDirEntry = new DirectoryEntry("WinNT://" + strDoamin);
        DirectoryEntries entries = obDirEntry.Children;
        DirectoryEntry obUser = entries.Add(strLogin, "User");
        obUser.Properties["FullName"].Add("Amigo");
        object obRet = obUser.Invoke("SetPassword", strPwd);
        obUser.CommitChanges();
      }
      catch (Exception ex)
      {
        Trace.Warn(ex.Message);
      }
    }
    

    But a real breakthrough has come via me signing up on Safari Books Online, and discovering a book there called "The .NET Developer's Guide to Directory Services Programming" - ISBN 10: 0-321-35017-0; ISBN 13: 978-0-321-35017-6

    This book seems tailor made for my dilemma as it explains all the basics of programming directory services, then gives specific examples for adding users, setting permissions, etc.