Home > Source Code > Net User Information and Security Using ActiveDS Type Library

Net User Information and Security Using ActiveDS Type Library

Public Function IsGroupMember(Username As String, _
DomainName As String, _
GroupName As String) As Boolean
‘=================================================
‘=================================================
‘   Purpose:    To determin if a user is a member of a specified group

‘   Syntax:     IsGroupMember(User Name, Domain Name, Group Name)

‘   Arguments:
‘               username        — login ID of user to verify
‘               DomainName      — Domain name the user and group reside in
‘                (Can also use IP Address of Primary Domain Controller)
‘               GroupName       — NT Group name to match the user to

‘   Example:    IsGroupMember(“myusername”, “mydomain”, “mygroupname”)
‘==========================================================
‘==========================================================
Dim usr As IADsUser, obj As Object, sOut() As String, i As Long
IsGroupMember = False
Set usr = GetObject(“WinNT://” & DomainName & “/” & Username & “,user”)
For Each obj In usr.Groups
If GroupName = obj.Name Then IsGroupMember = True
Next
End Function

Function IsGoodPWD(sUserName As String, DomainName As String, _
chkPassword As String) As Boolean
‘====================================================
‘=====================================================
‘   Purpose:    To determin if a password given is the correct network password for the specified user

‘   Syntax:     IsGoodPWD(User Name, Domain Name, Password)

‘   Arguments:
‘               username        — login ID of user to verify
‘               DomainName      — Domain name the user and group reside in
‘                           (Can also use IP Address of Primary Domain Controller)
‘               chkPassword     — Password to verify against the domain

‘   Example:    IsGoodPWD(“myusername”, “mydomain”, “mypass123″)
‘==============================================================
‘=========================================================
On Error GoTo MyError:
Dim usr As IADsUser
Set usr = GetObject(“WinNT://” & DomainName & “/” & sUserName & “,user”)
usr.ChangePassword chkPassword, “qinspwue4″
usr.ChangePassword “qinspwue4″, chkPassword
IsGoodPWD = True
Exit Function
MyError:
IsGoodPWD = False
End Function

Public Function ShowGroupMembers(DomainName As String, _
UserGroupName As String)
‘=========================================================
‘=========================================================
‘   Purpose:    To display the members of a specified user group

‘   Syntax:     ShowGroupMembers(Domain Name, User Group Name)

‘   Arguments:
‘               DomainName      — Domain name the user and group reside in
‘                            (Can also use IP Address of Primary Domain Controller)
‘               UserGroupName   — The name of the NT User Group

‘   Example:    Call ShowGroupMembers(“mydomain”, “mygroupname”)
‘============================================================
‘============================================================
Dim grp As IADsGroup, User As Object
Set grp = GetObject(“WinNT://” & DomainName & “/” & UserGroupName & “”)
For Each User In grp.members
Debug.Print User.Name
Next User
End Function

  1. No comments yet.
  1. No trackbacks yet.