[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

User Cannot Change Password problem

I have this c# code that works to check the "User Cannot Change Password" check box but how can I unckeck it.

Thanks
string PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}";
 
            string[] trustees = new string[] { @"NT AUTHORITY\SELF", "EVERYONE" };
 
            ActiveDs.IADsSecurityDescriptor sd = (ActiveDs.IADsSecurityDescriptor)user.Properties["ntSecurityDescriptor"].Value;
            ActiveDs.IADsAccessControlList acl = (ActiveDs.IADsAccessControlList)sd.DiscretionaryAcl;
            ActiveDs.IADsAccessControlEntry ace = new ActiveDs.AccessControlEntry();
            foreach (string trustee in trustees)
            {
                ace.Trustee = trustee;
                ace.AceFlags = 0;
                ace.AceType = (int)
                ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_DENIED_OBJECT;
                ace.Flags = (int)ActiveDs.ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT;
                ace.ObjectType = PASSWORD_GUID;
                ace.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CONTROL_ACCESS;
                acl.AddAce(ace);
            }
            sd.DiscretionaryAcl = acl;
            user.Properties["ntSecurityDescriptor"].Value = sd;
            user.CommitChanges();

Open in new window

0
scanet
Asked:
scanet
  • 3
1 Solution
 
AmericomCommented:
Usually check and uncheck is just a 1 instead of 0. Have you tried it yet?
0
 
scanetAuthor Commented:
Hi,

I think I tried that but I will give it another go this evening.

Thanks
0
 
scanetAuthor Commented:
I tried to change ace.AceFlags = 0; to 1 but it did not work. is there another metod I could use?

Thanks
0
 
scanetAuthor Commented:
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now