Jump to content

Member of Active Directory Group


Recommended Posts

  • Developers

I'm trying to code into a script some code that checks AD group membership for a specific group before executing the script. Any ideas would be greatly appreciated.

$oMyError = ObjEvent("AutoIt.Error", "ComError")
msgbox(0,"Validate",UserInGroup(@LogonDomain,"usernamer","groupname"))
Exit

; Check if User is in a group 
Func UserInGroup($Domain, $UserName, $InGroup)
    Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName)
    For $oGroup in $objUser.Groups
        If $oGroup.Name = $InGroup Then 
            Return 1
        EndIf
    Next
    Return 0
EndFunc 
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc   ;==>ComError

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$oMyError = ObjEvent("AutoIt.Error", "ComError")
msgbox(0,"Validate",UserInGroup(@LogonDomain,"usernamer","groupname"))
Exit

; Check if User is in a group 
Func UserInGroup($Domain, $UserName, $InGroup)
    Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName)
    For $oGroup in $objUser.Groups
        If $oGroup.Name = $InGroup Then 
            Return 1
        EndIf
    Next
    Return 0
EndFunc 
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc   ;==>ComError
Where do I place the AD group name to verify? Can't make it run as-is.
Link to comment
Share on other sites

  • Developers

Where do I place the AD group name to verify? Can't make it run as-is.

all you need to do is change this line:

msgbox(0,"Validate",UserInGroup(@LogonDomain,"usernamer","groupname"))oÝ÷ ÚÚ,¢g­)à)jëh×6If  UserInGroup(@LogonDomain,@UserName,"Your AD groupNamee") then
    msgbox(0,"Validate","User in your groupname")
Else
    msgbox(0,"Validate","User NOT in your groupname")
EndIf

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...