Jump to content
Sign in to follow this  
beb7089

Member of Active Directory Group

Recommended Posts

beb7089

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.

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
beb7089

$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.

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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
Sign in to follow this  

×