Jump to content

Check Group Membershp


Recommended Posts

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

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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