Sign in to follow this  
Followers 0
Alan D. Ayers

Users in a Windows Groups

3 posts in this topic

I am very new to AutoIT so far I like what I see. However I cannot find anything on checking if a user belongs to a Windows Group. Any help would be appreciated. Thanks.

Alan

Share this post


Link to post
Share on other sites



Transitioning out of Kix, are we? You could do it with WMI objects, but I've had problems with that not working very well on older machines, and being slow in general. But I stumbled upon another method. Try this:

#include <Constants.au3> ; required for StdoutRead

; populate $groupstring with the output of net user /domain
; remove the /domain if you are just interested in local machine groups
$foo = Run(@ComSpec & " /c net user "& @username &" /domain", @SystemDir, @SW_HIDE,$STDOUT_CHILD)
$groupstring = ""
While 1
    $groupstring &= StdoutRead($foo)
    If @error = -1 Then ExitLoop
Wend

func ingroup($which)
    if $which = "*" then return 1
    $which = stringleft($which, 21) ; net user /domain returns only the first 21 chars of each group
    $which = "*" & $which
    if stringinstr($groupstring,$which) then
        return 1
    else
        return 0
    endif
endfunc

;example usage
if ingroup("Domain Admins")
    $admin = true
else
    $admin = false
endif

You could also use part of this code for retrieving the output of a Kix script which enumerated domain group membership. Kix is pretty good at that.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

That is fabulous thank you very much. It is greatly appreciated. Now if a member is part of the group the application is installed/updated (using runasset for admin priviledges) otherwise the script will just exit. Thank you Thank you Thank you.

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  
Followers 0