Jump to content

Users in a Windows Groups


Alan D. Ayers
 Share

Recommended Posts

This is not the support forum


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Use the following code from Scriptomatic to help you get to your end. You will need to parse the output, but it will atleast get you started in a direction.

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "GroupComponent: " & $objItem.GroupComponent & @CRLF
      $Output = $Output & "PartComponent: " & $objItem.PartComponent & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_GroupUser" )
Endif

I hope it helps,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

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.

:P

Alan

Try the IsMember.exe from the Windows Resource Kit.

Sicapo

Link to comment
Share on other sites

Func UserInGroup($Domain, $UserName, $InGroup)
    Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName)
    For $oGroup in $objUser.Groups
        If $oGroup.Name = $InGroup Then 
            Return 1
        EndIf
    Next
    Return 0
EndFunc

Just specify the domain, username and what group to look for. Then use an IF statement to see if its true.

Edited by powaking
Link to comment
Share on other sites

another quick one would be something on the lines of this

$Name = InputBox("Group", "Enter User Name", "", "", 100, 100, 100, 100)
If @error Then Exit
If $Name = "" Then Exit
Local $objUser = ObjGet("WinNT://" & @LogonDomain & "/" & $Name)
For $oGroup in $objUser.Groups
    MsgBox(4096, "Groups", $oGroup.Name, 10)
Next
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...