Jump to content

WMI to know the group of a given user name


mary
 Share

Recommended Posts

@Maryt

This will get you going :

Dim $InGroup

$oMyError = ObjEvent("AutoIt.Error", "ComError")


If  UserInGroup(@LogonDomain,@UserName,"Administrators") then
    msgbox(0,"Validate",@LogonDomain &"/"&@UserName&" : User in your groupname " & $InGroup)
Else
    msgbox(0,"Validate",@LogonDomain &"/"&@UserName&" : User NOT in your groupname")
EndIf

Exit
; Check if User is in a group 
Func UserInGroup($Domain, $UserName, $InGroup)
    ;local $sRet
    Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName)
    
    For $oGroup in $objUser.Groups
        If $oGroup.Name = $InGroup Then  Return 1
    Next
    Return 0
EndFunc 

;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc ;==>ComError

regards

ptrex

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