472,778 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,778 software developers and data experts.

Update managers name in active directory?

I am trying to update the managers name in active directory with an application I got that updates active directory.

I been strugling with this for a few weeks now and couldn't find the best way to update the managers name.

I got a datareader that returns all the employees from the database then a method checks each one of the records and compares them in AD and them commits the changes to the users information.

This is what I have try so far:

This is one updates the other properties except the managers name:
Expand|Select|Wrap|Line Numbers
  1. using (DirectoryEntry manager = new DirectoryEntry(GetDirectoryEntry()))
  2.                 using (DirectoryEntry minion = new DirectoryEntry(GetDirectoryEntry())) {
  3.                   minion.Properties["manager"].Value =
  4.                       manager.Properties["distinguishedName"].Value.ToString();
  5.                 }
Error: The value provided for adsObject does not implement IADs.

With this is one:
Expand|Select|Wrap|Line Numbers
  1. if (oEmployee.Manager != String.Empty) {
  2.                   dentry.Properties["manager"].Value = "CN=oEmployee.Manager,DC=domain, DC=net";
Error: System.DirectoryServices.DirectoryServicesCOMExcep tion (0x8007202F): A constraint violation occurred.(Exception from HRESULT: 0x8007202F)

And with this one:
Expand|Select|Wrap|Line Numbers
  1. if (oEmployee.Manager != String.Empty) {
  2.                   dentry.Properties["manager"].Value = oEmployee.Manager;
Error: System.DirectoryServices.DirectoryServicesCOMExcep tion (0x8007202F): A constraint violation occurred.(Exception from HRESULT: 0x8007202F)



This is my code:

Expand|Select|Wrap|Line Numbers
  1.     public void ModifyUsers(SortedList<string , clsEmployee> colEmployee) {
  2.       clsEmployee oEmployee;
  3.       DirectoryEntry dentry;
  4.       string empId;
  5.  
  6.       DirectoryEntry de = GetDirectoryEntry();
  7.       DirectorySearcher dirsearcher = new DirectorySearcher(de);
  8.       dirsearcher.PageSize = 1000;
  9.  
  10.       dirsearcher.Filter = "(&(objectCategory=person)(objectClass=user))";
  11.       SearchResultCollection dsCol = dirsearcher.FindAll();
  12.  
  13.       foreach (SearchResult restEnt in dsCol) {
  14.         dentry = restEnt.GetDirectoryEntry();
  15.  
  16.         if (dentry.Properties["employeeId"] != null) {
  17.           if (dentry.Properties["employeeId"].Value != null) {
  18.             empId = dentry.Properties["employeeId"].Value.ToString();
  19.             oEmployee = new clsEmployee();
  20.             try {
  21.               oEmployee = colEmployee[empId];
  22.             }
  23.             catch {
  24.               //do nothing
  25.             }
  26.             if (!oEmployee.empId.Equals(string.Empty)) {            
  27.  
  28.               //Update the information
  29.               try {
  30.                 if (oEmployee.Pager != String.Empty) {
  31.                   dentry.Properties["pager"].Value = oEmployee.Pager;
  32.                 }
  33.                 if (oEmployee.TelephoneNumber != String.Empty) {
  34.                   dentry.Properties["telephoneNumber"].Value = oEmployee.TelephoneNumber;
  35.                 }
  36.                 if (oEmployee.HomePhone != String.Empty) {
  37.                   dentry.Properties["homePhone"].Value = oEmployee.HomePhone;
  38.                 }
  39.                 if (oEmployee.Mobile != String.Empty) {
  40.                   dentry.Properties["mobile"].Value = oEmployee.Mobile;
  41.                 }
  42.                 if (oEmployee.Nextel != String.Empty) {
  43.                   dentry.Properties["ipphone"].Value = oEmployee.Nextel;
  44.                 }
  45.                 if (oEmployee.RadioId != String.Empty) {
  46.                   dentry.Properties["otherIpPhone"].Value = oEmployee.RadioId;
  47.                 }
  48.                 if (oEmployee.Department != String.Empty) {
  49.                   dentry.Properties["department"].Value = oEmployee.Department;
  50.                 }
  51.                 if (oEmployee.Manager != String.Empty) {
  52.                   dentry.Properties["manager"].Value = oEmployee.Manager;
  53.                 }
  54.                 using (DirectoryEntry entryManager = new DirectoryEntry(GetDirectoryEntry()))
  55.                 using (DirectoryEntry dirent = new DirectoryEntry(GetDirectoryEntry())) {
  56.                   dirent.Properties["manager"].Value =
  57.                       entryManager.Properties["manager"].Value = oEmployee.Manager;
  58.                 }
  59.                 //Update managers name
  60.                 //if (oEmployee.Manager != String.Empty) {
  61.                 //  dentry.Properties["distinguishedName"].Value = oEmployee.Manager;
  62.                 //}
  63.               }
  64.               catch (Exception e) {
  65.                 //For debugging
  66.                 Console.WriteLine(e.Message);
  67.               }
  68.               dentry.CommitChanges();
  69.               dentry.Close();
  70.             }
  71.           }
  72.         }
  73.       }
  74.  
Any ideas of how I can update the manager name?

Thanks.
Oct 16 '08 #1
2 2631
Curtis Rutland
3,256 Expert 2GB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Oct 16 '08 #2
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Sorry, I forgot. I'll make sure to include them next time.

Thanks.
Oct 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
2
by: Paul Hadfield | last post by:
All, Can anyone help with an example of how to use the System.DirectoryServices name space? I've found examples on Google in C# but I've had no success trying to use them. Basically, I...
0
by: =?Utf-8?B?SmVhbmluZQ==?= | last post by:
Hi, can anyone tell me how I can update the publicDelegates active directory property using vb.net 2005 and System.DirectoryServices. I understand the publicDelegates property to be where 'send of...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.