Re: IsInRole does not seem to work

From: Shel Blauman [MSFT] (sheldonb_at_online.microsoft.com)
Date: 09/16/03


Date: Tue, 16 Sep 2003 08:48:18 -0700


Use the string machinename\customRole.

Shel

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"RDufour" <rdufour@sgiims.com> wrote in message
news:u226ud$eDHA.3248@tk2msftngp13.phx.gbl...
> How do you check to see if it's not a built-in user group like
> administrators or users, but other user groups created by the network
> administrator, like Sales, Personnel etc..
>
> Thanks for the help,
>
> Bob
>
> "Shel Blauman [MSFT]" <sheldonb@online.microsoft.com> wrote in message
> news:%23FscUF8eDHA.3788@tk2msftngp13.phx.gbl...
> > Try this code, it works for me:
> >
> > Imports System
> >
> > Imports System.Security.Principal
> >
> > Public Class TestIsInRole
> >
> > ' A simple sample to demonstrate how to test whether the current
> >
> > ' principal (user) is in a built-in role.
> >
> > Public Shared Sub Main()
> >
> > Dim id As WindowsIdentity
> >
> > id = WindowsIdentity.GetCurrent()
> >
> > Dim p As New WindowsPrincipal(id)
> >
> > Console.WriteLine("Am I an administrator? {0}",
> > p.IsInRole("builtin\administrators").ToString())
> >
> > Console.WriteLine("Am I an administrator? {0}",
> > p.IsInRole(WindowsBuiltInRole.Administrator).ToString())
> >
> > Console.WriteLine("Hit enter to exit")
> >
> > Console.ReadLine()
> >
> > End Sub 'Main
> >
> > End Class 'TestIsInRole
> >
> >
> >
> > Shel
> >
> >
> > -- 
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > Use of included script samples are subject to the terms specified at
> > http://www.microsoft.com/info/cpyright.htm
> >
> >
> > "RDufour" <rdufour@sgiims.com> wrote in message
> > news:OqpSLD8eDHA.2184@TK2MSFTNGP10.phx.gbl...
> > > No, I had to write (in vb)
> > >
> >
>
AppDomain.CurrentDomain.SetPrincipalPolicy(Principal.PrincipalPolicy.Windows
> > > Principal)
> > >
> > > But it does not work, I still always get false no matter what.
> > >
> > >
> > >
> > > Bob
> > >
> > > "Eugene V. Bobukh [MS]" <eugenebo@online.microsoft.com> wrote in
message
> > > news:ellEU57eDHA.1712@TK2MSFTNGP11.phx.gbl...
> > > Does it help if you set up current PrincipalPolicy to WindowsPrincipal
> > > before the first check? E.g.,
> > >
> > >
> > >
> >
>
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
> > > ;
> > >
> > >
> > > -- 
> > >
> > > Eugene V. Bobukh
> > >
> > > This message is provided "AS IS" with no warranties, and confers no
> > rights.
> > > Any opinions or policies stated within it are my own and do not
> > necessarily
> > > constitute those of my employer.
> > >
> > > ----
> > >
> > > "RDufour" <rdufour@sgiims.com> wrote in message
> > > news:OvfGVJ7eDHA.2344@TK2MSFTNGP10.phx.gbl...
> > > > The following code
> > > >
> > > > Dim myUser As System.Security.Principal.WindowsIdentity
> > > >
> > > > Dim winPrincipal As New
> > > >
> > >
> >
>
System.Security.Principal.WindowsPrincipal(System.Security.Principal.Windows
> > > > Identity.GetCurrent())
> > > >
> > > > Dim username As String = winPrincipal.Identity.Name
> > > >
> > > > If winPrincipal.IsInRole("Users") Then
> > > >
> > > > 'OK
> > > >
> > > > Else
> > > >
> > > > 'Not OK
> > > >
> > > > End If
> > > >
> > > > Always returns NOT OK even though while debugging I can see my
> username
> > > > correctly I can go to the local administration on my server that I
> > develop
> > > > om (w2k- SP4) see that my username Bob is part of users
administrators
> > and
> > > > part of Users. No matter what usergroup I write in (checking
> > > capitalization
> > > > is same) the isinRole function never returns True.
> > > >
> > > > Can anyone tell me what's wrong?
> > > >
> > > >
> > > >
> > > > Thanks in advance,
> > > >
> > > >
> > > >
> > > > Bob
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Using ldifde & csvde
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... > How can I get the Windows 2000 versions and will they work with a Windows ... >> Use of included script samples are subject to the terms specified at ...
    (microsoft.public.windows.server.active_directory)
  • RE: SQLSink Sample
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... Use of included script samples are subject to the terms specified at ...
    (microsoft.public.vsnet.enterprise.tools)
  • Re: Convert Express To Server
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... Use of included script samples are subject to the terms specified at ...
    (microsoft.public.sqlserver.setup)
  • Re: Lost admin access to ADAM
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... Use of included script samples are subject to the terms specified at ...
    (microsoft.public.windows.server.active_directory)
  • Re: Programmatically replicate an Active Directory partition
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... > Use of included script samples are subject to the terms specified at ...
    (microsoft.public.windows.server.active_directory)