Jump to content

objget logic


gcue
 Share

Recommended Posts

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
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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