EN / USD
32
of 76
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon
When I try to set Active Directory user properties, throw exception
TEP , The Engineering Projects , Calender Question: 07-Mar-2017
TEP , The Engineering Projects , Category In: Microsoft Visual Studio Projects
It`s a good day to die....

I`m trying to make & modify windows application about AD group and users.

This application works like this.

Users choose property and mapping it from source data(DB or Excel files...)

And press sync start button, that properties put into the AD User.

But When I set AD user`s properties, it throws exception like this in DirectoryEntry.CommitChanges(); block.

The directory
service cannot perform the requested operation on the RDN attribute of an object.

Sadly I`m a newbie of Active Directory, I don`t know how to solve it... Please help me.

Code is below. [code]void CreateADUser(string ppk,string pk,DataRow row) { string pass = GetPass(pk,row,LogSections.AD); DirectoryEntry addept = adm.FindOU(ppk); string sOU = adm.GetPrincipalPath(addept); var aduser = adm.CreateNewUser(sOU, pk, pass, pk, null, null, adm.sDomain); SetAdUserProperties(pk, pass, row); MoveUser(ppk,pk); } void SetAdUserProperties(string pk,string pass,DataRow row) { if (row == null) return; List<ADMapping> MappingPatterns = GetAdMappings(Words.User,false); var colnames = Tool.GetColNames(row); var aduser = adm.GetUser(pk); var de=aduser.GetUnderlyingObject() as DirectoryEntry; foreach (var ADMap in MappingPatterns) { string val = ADMap.Mapping; val=Util.ReplaceColPattern(val, row); SetProperty(de, ADMap.CN, val); } if (!string.IsNullOrWhiteSpace(pass)) { var UserPkColumn = AppConfigHelper.GetAppString(Words.SourceUserPKColumn); UserPkColumn = Util.GetActualColName(UserPkColumn); aduser.SetPassword(pass); QueryHelper.Update(QueryHelper.ConnectionString, Words.ShadowUserTable ,new SqlParameter[] { new SqlParameter("@passwd", pass) } , new SqlParameter("@"+UserPkColumn,pk)); } aduser.Save(); } public void SetProperty(DirectoryEntry oDE, string sPropertyName, object sPropertyValue) { if (sPropertyValue != null && !string.IsNullOrWhiteSpace(sPropertyValue.ToString())) { if (oDE.Properties.Contains(sPropertyName)) { oDE.Properties[sPropertyName].Value = sPropertyValue; } else { oDE.Properties[sPropertyName].Add(sPropertyValue); } try { oDE.CommitChanges(); //exception here. oDE.Close(); } catch (Exception) { } } }[/code]
TEP , The Engineering Projects , Icon Answer: 0 TEP , The Engineering Projects , Icon Views: 150 TEP , The Engineering Projects , Icon Followers: 85
Small Bio
TEP , The Engineering Projects , Tags
PLC
Robot
STM32
Arduino
AI
ESP32
Ladder Logic
PLC Projects
Programming
Communicates STM32
PLC Projects
Communicates PLC
Font Style
Alignment
Indenting and Lists
Insert Media
Insert Items

Want to leave an answer!

Word Count :0 Draft Saved at 12:42 am.