Hi,
I've spent hours on google trying to find out how to check if a user account is locked out or not. All it does at the moment is say that all of the accounts are locked out :S even when i know for a fact that they aren't. Any help would be greatly appreciated.
This is the code i have so far.....
THE FUNCTION
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-
Function IsAccountDisabled()
Dim objUser
Dim objConnection
Dim objCommand
Dim FindUser
Dim strUser
Dim objRecordSet
Dim Wscript
Dim strExch
Dim strMailServer
Dim strOU
Dim strOUldap
Dim strLock
Dim strLockStatus
Const ADS_SCOPE_SUBTREE = 2
'GET USERNAME
On Error Resume Next
objConnection = CreateObject("ADODB.Connec
tion")
objCommand = CreateObject("ADODB.Comman
d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open("Active
Directory Provider")
objCommand.ActiveConnectio
n = objConnection
FindUser = (Username.Text)
If FindUser = "" Then
MsgBox("No Username enter, Exiting Script", MsgBoxStyle.OkOnly, "Nothing Entered")
Else
strUser = FindUser
End If
objCommand.Properties("Pag
e Size") = 1000
objCommand.Properties("Sea
rchscope")
= ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=sirrus,dc=com'W
HERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
objRecordSet = objCommand.Execute
objRecordSet.MoveFirst()
Do Until objRecordSet.EOF
objUser = (objRecordSet.Fields("dist
inguishedN
ame").Valu
e)
objRecordSet.MoveNext()
Loop
IsAccountDisabled = objUser.AccountDisabled
End Function
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
The bit to actually put a value in a text box...
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
'GET AND DISPLAY LOCKOUT STATUS
If IsAccountDisabled(objUser)
Then
AccountLock.Text = "ACCOUNT LOCKED"
Else
AccountLock.Text = "No"
End If
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
I'll admit.. this is my first ever attempt at doing anything with Visual Basic and i'm quite shocked i got the rest of the user information to display... it's just this one thing keeps showing that all of the accounts i enter are locked out.
Start Free Trial