Jump to content
Sign in to follow this  
PayneBack3

Check Group Membershp

Recommended Posts

PayneBack3

Im trying to create a script to install software only if the user is in s specific group,but it does not seem to work,everytime it sas that im not a member.

Please Assist.

$Groupmember=Runwait ("ifmember.exe /v Admin") ;check for membership of Admin-Users

if Not $Groupmember Then

MsgBox (16, "Error!", "User is not a member of Admin-Users")

Exit (1)

EndIf

Share this post


Link to post
Share on other sites
water

If you want to check membership for an Active Directory group you can use the AD UDF (for download please see my signature).

Function _AD_IsMemberOf() will do what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
PayneBack3

Hi water thanks for the response

i'm new on Autoit

can you please show me an example how to check membership ?

Thanks.

Share this post


Link to post
Share on other sites
water

Hi water thanks for the response

i'm new on Autoit

can you please show me an example how to check membership ?

Thanks.

When you download the AD UDF there is an example script for every function. Please see file _AD_IsMemberOf.au3

The script first gets a list of all groups the user is a member of and then checks if the user is a member of the first group. This always returns true but the script checks every other possible return codes and therefore should give you an idea how to solve your problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Country73

Im trying to create a script to install software only if the user is in s specific group,but it does not seem to work,everytime it sas that im not a member.

Please Assist.

$Groupmember=Runwait ("ifmember.exe /v Admin") ;check for membership of Admin-Users

if Not $Groupmember Then

MsgBox (16, "Error!", "User is not a member of Admin-Users")

Exit (1)

EndIf

Just so you have an example for using "ifmember". I still bounce over to it once in a while.

#include <Array.au3>
#include <Constants.au3>

Local $ifMem = "\\xena.statestr.com\LOGON\KansasCity\ifmember.exe"

Local $foo = Run(@ComSpec & " /c " & $ifMem & " /l",@SystemDir,@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
Local $line
Local $aGroups

;Read all details from IFMEMBER
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    If Not $line = "" Then $aGroups &= StringUpper($line)
WEnd

;Split each group to handle individually
Local $mSplit = StringSplit($aGroups,@LF)

;Extract first of each line so only Group Name remains
Local $Output
For $a = 1 To $mSplit[0]
    $Output = StringReplace($mSplit[$a],"USER IS A MEMBER OF GROUP ","")
    _ArraySwap($mSplit[$a],$Output)
Next

;Sort Groups alphabetically so search is quicker, display for example
_ArraySort($mSplit,0,1)
_ArrayDisplay($mSplit,'Groups')
Exit

You can now search through the Array to look for the specific group membership.

Hope that works out for you as well.

[Edit]

I run it in this manner since I generally have my script to look for several different group memberships to run different things.

Edited by Country73

If you try to fail and succeed which have you done?AutoIt Forum Search

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  

×