Scenario

 

On machines where Vista/W7 is installed there appears to be an issue when checking to see if a user is in a role.  User Account Control (UAC) must be on to reproduce the issue.  The result is that the value returned is always FALSE even when the user does belong to the group.

 

Sample Code (UAC must be on to produce error)

 

If My.User.IsInRole(“My Domain\My Group”) Then

     Return True

Else

     Return False

End If

Workaround

 

To get around this I created a function using other .Net functions.

Public Function IsInUserRole(ByVal RoleToFind As String) As Boolean

    Dim id As WindowsIdentity = WindowsIdentity.GetCurrent
    Dim irc As IdentityReferenceCollection

    ‘ Gets a SID list of groups the user belongs to

    irc = id.Groups

    For Each ir As IdentityReference In irc

        ‘ Need to convert the SID to plain english

Technorati Tags: ,,


        Dim act As NTAccount = CType(ir.Translate(Type.GetType("System.Security.Principal.NTAccount")), NTAccount)

        If act.Value = RoleToFind Then

            Return True

        End If

    Next

    Return False

End Function

Share this blog article:
  • Print
  • Facebook
  • del.icio.us
  • Digg
  • Yahoo! Buzz
  • Google Bookmarks
  • Slashdot
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Related Posts

  • No Related Post