Jump to content

Users in a Windows Groups


Recommended Posts

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]

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