public void MssUser_Create(string ssUsername, string ssPassword, string ssPath, string ssNewUsername, string ssNewPassword, string ssUserDescription, string ssGroup, string ssMail) { DirectoryEntry AD = null; DirectoryEntry NewUser = null; DirectoryEntry group = null; try { // if not valid it will raise an exception AD = getValidDirectoryEntry(NormalizeLDAPPath(ssPath), ssUsername, ssPassword); NewUser = AD.Children.Add("CN=" + ssNewUsername, "user");
protected DirectoryEntry getValidDirectoryEntry(string ssPath, string ssUsername, string ssPassword) { DirectoryEntry e = null; try { e = new DirectoryEntry(ssPath, ssUsername, ssPassword); try { if (e.Name == "") throw new Exception(); } catch (Exception) { throw new Exception("Could not find usable entry in path"); } } finally { if (e != null) { e.Close(); e.Dispose(); } } return e; }