PayneBack3 Posted May 19, 2010 Posted May 19, 2010 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
water Posted May 19, 2010 Posted May 19, 2010 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: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
PayneBack3 Posted May 19, 2010 Author Posted May 19, 2010 Hi water thanks for the response i'm new on Autoit can you please show me an example how to check membership ? Thanks.
water Posted May 19, 2010 Posted May 19, 2010 On 5/19/2010 at 12:31 PM, 'PayneBack3 said: Hi water thanks for the responsei'm new on Autoitcan 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.au3The 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: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Country73 Posted May 19, 2010 Posted May 19, 2010 (edited) On 5/19/2010 at 8:18 AM, 'PayneBack3 said: 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 May 19, 2010 by Country73 If you try to fail and succeed which have you done?AutoIt Forum Search
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now