Sign in to follow this  
Followers 0
mary

WMI to know the group of a given user name

4 posts in this topic

Just about WMI, how we can get the group of a given username: some thing like this " GetGroup($UserName) " ?

thinks

Share this post


Link to post
Share on other sites



@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

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