Discussion:
NEWBIE - Unlocking an AD user with VB.NET
(too old to reply)
David Walker
2004-05-21 19:56:30 UTC
Permalink
I'm attempting to create an ASP.NET application using Visual Basic
with Visual Studio 2003. The purpose of this web application is to
populate a listbox with the names of AD users whose accounts are
locked (the "lockouttime" property is nonzero) when the form loads,
and to allow the admin to select a name from the list and click a
button which unlocks the selected user.

I am using the "system.directoryservices" namespace to access my
company's Active Directory.

So far, I have successfully populated my list box and can retrieve a
list of the AD properties associated with the selected user.

This is where I start to get into unknown territory; I would
appreciate it very much if anyone here could point me towards some
sample vb.net code or perhaps a tutorial that would explain how one
might go about programatically unlocking a user in the AD.

Thanks for your time.

David Walker
Niclas Lindblom
2004-05-25 19:37:30 UTC
Permalink
Hi,

Here is the function that I use for a similar application:

Public Function UnlockAccount(ByVal Username As String) As Boolean
Dim dirRootEntry As DirectoryEntry
Dim dirUser As DirectoryEntry
Dim dirSearcher As DirectorySearcher
Dim dirresult As SearchResult

Try

dirRootEntry = New
DirectoryEntry("LDAP://OU=myOU,DC=myDomain,DC=Com")
dirSearcher = New DirectorySearcher(dirRootEntry)

dirSearcher.Filter = "(Displayname=" & Username & ")"

dirresult = dirSearcher.FindOne
dirUser = New DirectoryEntry(dirresult.Path)

dirUser.Properties("LockOutTime").Value = 0

dirUser.CommitChanges()
Return True
Catch ex As Exception
evtLog.WriteEntry("UnlockAccount: " & ex.Message & " " &
WindowsIdentity.GetCurrent.Name)
Return False
End Try
End Function

Hope this helps

Regards

Niclas Lindblom
Post by David Walker
I'm attempting to create an ASP.NET application using Visual Basic
with Visual Studio 2003. The purpose of this web application is to
populate a listbox with the names of AD users whose accounts are
locked (the "lockouttime" property is nonzero) when the form loads,
and to allow the admin to select a name from the list and click a
button which unlocks the selected user.
I am using the "system.directoryservices" namespace to access my
company's Active Directory.
So far, I have successfully populated my list box and can retrieve a
list of the AD properties associated with the selected user.
This is where I start to get into unknown territory; I would
appreciate it very much if anyone here could point me towards some
sample vb.net code or perhaps a tutorial that would explain how one
might go about programatically unlocking a user in the AD.
Thanks for your time.
David Walker
Loading...