Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3330646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:30:40+00:00 2026-05-17T23:30:40+00:00

I have been working with System.DirectoryServices for a while in a project involving Active

  • 0

I have been working with System.DirectoryServices for a while in a project involving Active Directory. I am curious on the implementation of the UserAccountControl property to control the attributes of a particular account. If I wanted to implement settings in my own applications using a combination of bytes to determine the state of x or y setting, how would I go about doing this in C#? Say that I would like to implement a useraccountcontrol property on my own class and I want to use a combination of bytes to determine which permissions the account should have.

Here is the way it is modified in Active Directory:
http://support.microsoft.com/kb/305144

and here is the place with the object definition:
http://msdn.microsoft.com/en-us/library/ms680832%28VS.85%29.aspx

Edit:

Say that I have a User class of my own and I want to implement a property similar to the way UserAccountControl is implemented in Active Directory. Let’s say I want to have a set of four bytes storing the settings.

I want to use the last byte to determine the account status,
0 = Account Inactive 1= Account Active 2=Account Expired 4=Some Other Status 8=Yet Another Status.

Then the next byte to the left I want to contain the account type:
16=Admin Account, 32=Regular Account, 64=Guest Account, 128 = Other Account.

Then use the next byte to the left to set some other setting so that
256 = something, 512 = something else, 1024 = something else, etc.

I would like to combine this to use bitwise combinations to set the account properties. I have the idea in my head, but I am not sure how to implement it, or if it even makes sense what I am trying to do.

Edit:
After receiving the answer and doing some more digging I found this link that talks more about setting Flags: http://msdn.microsoft.com/en-us/library/ms229062.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:30:40+00:00Added an answer on May 17, 2026 at 11:30 pm

    Let’s define a helper type:

    [Flags]
    public enum UserAccountControl {
        // values from http://support.microsoft.com/kb/305144
        Script = 0x0001,
        AccountDisabled = 0x0002,
        HomeDirRequired = 0x0008,
        Lockout = 0x0010,
        PasswordNotRequired = 0x0020,
        PasswordCantChange = 0x0040,
        EncryptedTextPasswordAllowed = 0x0080,
        TempDuplicateAccount = 0x0100,
        NormalAccount = 0x0200,
        InterDomainTrustAccount = 0x0800,
        WorkstationTrustAccount = 0x1000,
        ServerTrustAccount = 0x2000,
        DontExpirePassword = 0x10000,
        MnsLogonAccount = 0x20000,
        SmartcardRequired = 0x40000,
        TrustedForDelegation = 0x80000,
        Delegated = 0x100000,
        UseDesKeyOnly = 0x200000,
        DontReqPreauth = 0x400000,
        PasswordExpired = 0x800000,
        TrustedToAuthForDelegation = 0x1000000
    }
    

    You can cast between int and enum types (I’m assuming you know how to get one of these values as an integer). Then you could manipulate values using the bitwise operators as follows:

    void manipulateUserFlags(UserAccountControl uac) {
        // Set the SCRIPT flag (bitwise OR)
        uac |= UserAccountControl.Script;
    
        // Clear the ACCOUNTDISABLE flag (complement, bitwise AND)
        uac &= ~UserAccountControl.AccountDisabled;
    
        // Check for the HOMEDIR_REQUIRED flag (bitwise AND)
        if((uac & UserAccountControl.HomeDirRequired) != UserAccountControl.None) {
            // ...
        }
    
        // Toggle the NORMAL_ACCOUNT flag (bitwise XOR)
        uac ^= UserAccountControl.NormalAccount;
    
        // Check for several types of trust, and a required password
        if((uac & UserAccountControl.WorkstationTrustAccount
                & UserAccountControl.ServerTrustAccount
                & ~UserAccountControl.PasswordNotRequired) != UserAccountControl.None) {
            // ...
        }
    }
    

    Those are the same bitwise operators that work for integers, but enum types are recommended in C# because they are more strongly-typed. Bitwise manipulation of integers makes a lot more sense in C or C++, because you can test directly on integers in conditionals and because those languages aren’t as strongly-typed anyway.

    However, if you are going to be implementing this as part of a library, or doing these operations commonly, I’d consider putting more of a design around it, with several enum-based properties that represent groups of similar settings, and int ToADValue and UserAccountControl FromADValue methods. This would give you a clear place to put any validation logic, and it would make code that manipulates these properties even more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that adds elements to an AutoCad drawing. I noticed that
I have a snippet to create a 'Like' button for our news site: <iframe
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
Let say I have the following desire, to simplify the IConvertible's to allow me
I am attempting to pull some information from my tnsnames file using regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.