Hi,
I am trying to check whether a User passed for LDAP Server is Enabled or not and IsLocked or not. But I am not getting its properties values, though it is showing me properties count as 42.
Can you please tell me these things.
- how to get the properties values ?
- Specially with which properties to check UserEnabled or Locked out ?
- how to know all property names ?
- I am using 2003 server at present, will this code work with any OS ?
Here is my function.
########################################################################
Public Enum AdsUserFlags
Script = 1
AccountDisabled = 2
HomeDirectoryRequired = 8
AccountLockedOut = 16
PasswordNotRequired = 32
PasswordCannotChange = 64
EncryptedTextPasswordAllowed = 128
TempDuplicateAccount = 256
NormalAccount = 512
InterDomainTrustAccount = 2048
WorkstationTrustAccount = 4096
ServerTrustAccount = 8192
PasswordDoesNotExpire = 65536
MnsLogonAccount = 131072
SmartCardRequired = 262144
TrustedForDelegation = 524288
AccountNotDelegated = 1048576
UseDesKeyOnly = 2097152
DontRequirePreauth = 4194304
PasswordExpired = 8388608
TrustedToAuthenticateForDelegation = 16777216
NoAuthDataRequired = 33554432
End Enum
Public Function UserExists( _
ByVal LDAPServerConnectionString As String, _
ByVal UserName As String, _
ByVal UserPassword As String, _
Optional ByVal CheckIsUserAccountEnabled As Boolean = False, _
Optional ByVal CheckIsUserAccountLocked As Boolean = False) As Boolean
UserExists = False
Dim de As New DirectoryEntry(LDAPServerConnectionString
Try
If UserName.Length > 0 Then
de.Username = UserName
End If
If UserPassword.Length > 0 Then
de.Password = UserPassword
End If
'This method is to validate user
Try
de.RefreshCache()
Catch ex As Exception
Return False
End Try
'msDS-User-Account-Control-Computed 'userAccountControl
Dim userFlags As AdsUserFlags = CType(de.Properties("userAccountControl").Value, AdsUserFlags)
MsgBox(String.Format("AdsUserFlags for {0}: {1}", de.Path, userFlags))
Return True
Catch exUser As System.DirectoryServices.DirectoryServicesCOMException
Return False
Catch ex As Exception
Throw ex
End Try
End Function
########################################################################