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

  • Home
  • SEARCH
  • 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 7548515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:43:05+00:00 2026-05-30T09:43:05+00:00

I’m trying to figure out how to set the User cannot change password attribute

  • 0

I’m trying to figure out how to set the “User cannot change password” attribute of AD using VB.NET.

I was originally hoping to use the UserAccountControl Flags found here http://support.microsoft.com/kb/305144 but I realized you cannot set the PASSWD_CANT_CHANGE flag like one would expect. This lead me to this posting Preventing an Active Directory user from changing his/her password using DirectoryServices but I cannot get the saving working.

Here’s the code I have right now.

        Dim domainContext As PrincipalContext = New PrincipalContext(ContextType.Domain)
        Dim user As UserPrincipal = UserPrincipal.FindByIdentity(domainContext, "user5")
        user.UserCannotChangePassword = True
        user.Save(domainContext)

Every time I try to do a save on this I get an InvalidOperationException. The documentation for this isn’t too helpful either: http://msdn.microsoft.com/en-us/library/bb335863.aspx

What’s strange to me is that if I set a different attribute of that UserPrincipal object, like the SamAccountName, saving works fine, but once I introduce that UserCannotChangePassword attribute, saving fails.

I’ve verified that the user I am using to perform this action has proper privileges, but I’m not to sure where to go from here… Any ideas?

  • 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-30T09:43:06+00:00Added an answer on May 30, 2026 at 9:43 am

    Found an old school way to do this, thanks for pointing me in the right direction @juergen d. Guess I’ll have to settle.

            Dim objThisUser As IADs
            Dim intUserFlags As Integer
    
            ' Bind to the user object with the current credentials.
            objThisUser = GetObject("WinNT://" + gstrDomain + "/" + "user5")
    
            intUserFlags = objThisUser.Get("userFlags")
    
            'can't change
            intUserFlags = intUserFlags Or ADS_UF_PASSWD_CANT_CHANGE
    
            ' Modify the userFlags property.
            objThisUser.Put("userFlags", intUserFlags)
    
            ' Commit the changes
            objThisUser.SetInfo()
    

    I was close the whole time to having a perfect solution, but just couldn’t get the saving to work. This works fine I guess. Using this just means a few more lines of code, and a bit less adaptability.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.