Share my code to solve the problem mentioned above:
Imports System.Director yServices
'Lock:
Public Function lockAcct(ByVal acct2Lock As String) As Boolean
Dim blnreturn As Boolean = False
Dim i As Integer = 0
Dim path As String = gstrActiveDirec tory
Dim user As DirectoryEntry = Nothing
Try
'since it's hard to use code to lock an account, use 4 attempts
to login and let AD handle it
'line1 section is to try to login using 1 as password
Line1:
i = i + 1
user = New DirectoryEntry( path, acct2Lock, 1)
Dim nativeObject As Object = user.NativeObje ct
'line2 section is to confirm the account has been locked
Line2:
Dim user2 As DirectoryEntry = adUser(acct2Loc k)
If Convert.ToBoole an(user2.Invoke Get("IsAccountL ocked")) Then
blnreturn = True
End If
Catch ex As Exception
If i < 4 Or i = 4 Then
GoTo Line1
End If
GoTo Line2
End Try
Return blnreturn
End Function
'Unlock:
Public Function unlockAcct(ByVa l userid As String) As String
Dim strReturn As String = ""
Dim path As String = gstrActiveDirec tory
Dim entry As DirectoryEntry = New DirectoryEntry( path)
Try
Dim searcher As New
System.Director yServices.Direc torySearcher(en try)
searcher.Filter =
"(&(objectClass =user)(objectCa tegory=person)( sAMAccountName= " & userid &
"))"
searcher.Proper tiesToLoad.Add( "adspath")
Dim Result As System.Director yServices.Searc hResult =
searcher.FindOn e()
If Not Result Is Nothing Then
Dim user As New
DirectoryServic es.DirectoryEnt ry(Result.Path)
Try
user.Properties ("LockOutTime") .Value = 0 'unlock account
user.CommitChan ges()
user.Close()
strReturn = "successful "
Catch err As UnauthorizedAcc essException
strReturn = err.Message
End Try
Else
strReturn = "No such user in the active directory"
End If
Catch ex As Exception
'do something here
End Try
Return strReturn
End Function
"Lidia" <ll*@omnitrans. comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Anybody has any ideas?