Skip to content
@JaredMeredith

@JaredMeredith

Learn. Share. Repeat.

  • Blog
  • About Me
  • Strengths Finder Top 5
    • Strengths Finder All 34
  • 16Peronalities
  • Builder Profile 10

Tag: account

Active Directory, Programming, VB, Web, Web Service

Unlock Or SetPassword For An Active Directory Account Within A Web Application (VB)

05/22/201504/25/2016 Jared Meredith

Wrote a variation of this for different purposes over the past few months. You can get creative and put it in a web service or within your web application. You would also want to send a lot of the initial variables in through ByVal when you call the Function or Method.

Dim user As String = "yourdomain/userToUnlock"
Dim pwd As String = "userToUnlockPW"
Dim de As DirectoryEntry = Nothing
Dim ds As DirectorySearcher = Nothing
Dim url As String = "LDAP://111.11.111.1111/dc=yourdomain,dc=com"
de = New DirectoryEntry(url)
de.Username = "yourdomain/authorizedADuser"
de.Password = "authorizedADuserPW"
de.AuthenticationType = AuthenticationTypes.Secure Or AuthenticationTypes.ServerBind Or AuthenticationTypes.Sealing
ds = New DirectorySearcher(de)
ds.SearchRoot = de
ds.Filter = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", user)
ds.PropertiesToLoad.Add("userAccountControl")
Dim result As SearchResult = ds.FindOne
If Not result Is Nothing Then
de = result.GetDirectoryEntry
de.RefreshCache()
de.Properties("LockOutTime").Value = 0
de.Properties("userAccountControl").Value = &H200
de.Invoke("SetOption", New Object() {6, 6})
de.Invoke("SetOption", New Object() {7, 1})
de.Invoke("SetPassword", New Object() {pwd})
de.CommitChanges()
de.Close()
End If

Help me out and share!

  • Email a link to a friend (Opens in new window) Email
  • Print (Opens in new window) Print
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr
  • More
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Pocket (Opens in new window) Pocket
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
Like Loading...
Tagged account, active directory, password, SetPassword, unlock, userAccountControl, vb

About Me

Jared Meredith

Jared Meredith

Verified Services

View Full Profile →

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 75 other subscribers

Why did I start the site…?

I started this site mainly as a place where I can put any gotchas and snafus I find along the way to better help the development community. I hope it helps as time goes on.

Questions? Comments?

If you have a question about a post then please leave a comment. I'll reply on the comment to keep all answers for everyone to see. If you have a private technical inquiry unrelated to any posts, please direct it to jared.meredith@live.com.

The Latest

  • Step-by-Step Guide to Deploy Azure Static Web Apps
  • Optimizing Enterprise Architecture Initiatives: Partnering Model and Essential Stages
  • Remember the 5-9, not just the 9-5!
  • Presentation Now Available: The Power of Cross-Platform Automated Web-Based Testing in CICD Pipelines
  • TLDR: Reflection + Pain = Progress

Categories

Create a website or blog at WordPress.com
  • Subscribe Subscribed
    • @JaredMeredith
    • Join 75 other subscribers
    • Already have a WordPress.com account? Log in now.
    • @JaredMeredith
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d