Re: Get the Domain-Groups of a User?

From: Rob Windsor [MVP] (rwindsor_at_NO.MORE.SPAM.bigfoot.com)
Date: 02/13/04


Date: Fri, 13 Feb 2004 09:16:46 -0500

The .NET Framework provides a way to check if the user is in a specific
role. For example if I wanted to check if the current user was part of the
group "Accounting" I would make this call:

System.Threading.Thread.CurrentPrincipal.IsInRole("Accounting")

It doesn't appear that you can easily get a list of all the roles. The
WindowsIdentity class does keep an internal list of roles but it does not
expose a public method to access the list. You can use reflection to get
this list but be carefull, because this code is accessing an internal
variable there is no guarantee that it will work in upcoming versions of
.NET

Imports System.Security.Principal
Imports System.Security
Imports System.Reflection

Dim id As WindowsIdentity
Dim result As Object
Dim roles() As String

id = WindowsIdentity.GetCurrent()
result = GetType(WindowsIdentity).InvokeMember( _
    "_GetRoles", _
    BindingFlags.Static Or _
    BindingFlags.InvokeMethod Or _
    BindingFlags.NonPublic, _
    Nothing, id, New Object() {id.Token}, Nothing)
roles = DirectCast(result, String())

-- 
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"P Dietz" <anonymous@discussions.microsoft.com> wrote in message
news:61104147-62B1-4ABB-AC65-471056E0F332@microsoft.com...
> Hello,
> how can i get the groupslist, of which the current Windows-User is a
member?
>
> Thanks!
> Peter


Relevant Pages

  • Re: Importing text, etc. on remote .mdb file
    ... You can then use VBA string functions to get from there to the ... Is there an easy way to schedule the imports of the text files so I ... 'Modify strSQL and filenames as required ... Dim oJet 'DAO.DBEngine ...
    (microsoft.public.access.externaldata)
  • RE: Logon Error
    ... > Imports CrystalDecisions.CrystalReports ... > function is emailPDFwhich calls ChangeLogOnInfo EmailPDF returns a Report ... > Dim szErrorMailSecondary As String 'This is where all the mail messages ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Eval code and AppDomains
    ... Do you know of any other way to Eval a String to get a Boolean result other ... >> Dim objEval As New EvalProvider ... >> Imports Microsoft.VisualBasic ...
    (microsoft.public.dotnet.framework.aspnet)
  • Logon Error
    ... OK why does the following code work in a Windows form with a crystal report ... Imports CrystalDecisions.CrystalReports ... Dim szErrorMailSecondary As String 'This is where all the mail messages ...
    (microsoft.public.dotnet.framework.aspnet)
  • Single Signon Problem
    ... from the book "Microsoft sharepoint Building Office 2003 ... Dim objContext As WindowsImpersonationContext ... Dim arrCredentialsAs String ... Dim objIdentity As WindowsIdentity ...
    (microsoft.public.sharepoint.portalserver.development)