Jump to content
Sign in to follow this  
gcue

objget logic

Recommended Posts

gcue

im trying to perform a check to see if the person running the script has access to a group on a local machine. but the members of that group might be domain groups. so im trying to First, check the membership on that local group. and check those groups on the domain to see if the user running the script has access...

im loosing the logic somewhere..

$strGroup = "netsupport_control_users"

    $objGroup = ObjGet("WinNT://" & $asset & "/" & $strGroup)
    $objUser = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)
    
    Dim $aAdministrators[1]
    For $objMember In $objGroup.Members()
    
        For $oGroup in $objUser.Groups
    ;MsgBox(4096,"groups", $oGroup.Name, 10)
            If $oGroup.Name = $objGroup Then
                $flag = +1
            EndIf
        Next    
    Next
    

If $flag = 1 Then
    MsgBox(0,"","YES")
Else
    MsgBox(0,"","NO")
EndIf

Share this post


Link to post
Share on other sites
Skruge

This should give you direct membership, as well as one group down. The console output tells you the difference.

If you have nested groups, you would need to add some recursion.

$objGroup = ObjGet("WinNT://" & $asset & "/" & $strGroup)
$objUser = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)

Dim $aAdministrators[1]

Local $sGroups = ""
For $oGroup In $objUser.Groups
    $sGroups &= $oGroup.Name & @TAB
Next
$aGroups = StringSplit($sGroups, @TAB)

For $objMember In $objGroup.Members()
    If $objMember.Name = $objUser.Name Then
        ConsoleWrite($objUser.Name & " is a direct member of " & $objGroup.Name & @CRLF)
        $flag = +1
        ExitLoop
    EndIf
    For $iX = 1 To $aGroups[0]
        If $objMember.Name = $aGroups[$iX] Then
            ConsoleWrite($objUser.Name & " is a member of " & $objGroup.Name & " via " & $objMember.Name & @CRLF)
            $flag = +1
            ExitLoop (2)
        EndIf
    Next
Next


If $flag = 1 Then
    MsgBox(0, "", "YES")
Else
    MsgBox(0, "", "NO")
EndIf

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites
gcue

thanks ill try it when i go to work tomorrow!!

Share this post


Link to post
Share on other sites
gcue

works great!

thanks!!!

This should give you direct membership, as well as one group down. The console output tells you the difference.

If you have nested groups, you would need to add some recursion.

$objGroup = ObjGet("WinNT://" & $asset & "/" & $strGroup)
$objUser = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)

Dim $aAdministrators[1]

Local $sGroups = ""
For $oGroup In $objUser.Groups
    $sGroups &= $oGroup.Name & @TAB
Next
$aGroups = StringSplit($sGroups, @TAB)

For $objMember In $objGroup.Members()
    If $objMember.Name = $objUser.Name Then
        ConsoleWrite($objUser.Name & " is a direct member of " & $objGroup.Name & @CRLF)
        $flag = +1
        ExitLoop
    EndIf
    For $iX = 1 To $aGroups[0]
        If $objMember.Name = $aGroups[$iX] Then
            ConsoleWrite($objUser.Name & " is a member of " & $objGroup.Name & " via " & $objMember.Name & @CRLF)
            $flag = +1
            ExitLoop (2)
        EndIf
    Next
Next


If $flag = 1 Then
    MsgBox(0, "", "YES")
Else
    MsgBox(0, "", "NO")
EndIf

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.