473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Check group member ship or a user

Hello there
Is there a way through dotNet to check if a certain user is a member of a
specific group?
I use ADSI to get the memberships of the user then compare them to the group
I want to check, but this way the user has to be a member of this group
directly and if he is a member of a group that is a member of that group he
will not be considered a member of the group I am checking although he is
implicitly.
so basically what I need is a method that takes the user name and the group
name and check if this user is a member both implicitly or explicitly.
Any ideas?
Regards
Sameh
Nov 21 '05 #1
9 3745
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
Hello there
Is there a way through dotNet to check if a certain user is a member of a
specific group?
I use ADSI to get the memberships of the user then compare them to the
group I want to check, but this way the user has to be a member of this
group directly and if he is a member of a group that is a member of that
group he will not be considered a member of the group I am checking
although he is implicitly.
so basically what I need is a method that takes the user name and the
group name and check if this user is a member both implicitly or
explicitly.
Any ideas?
Regards
Sameh

Nov 21 '05 #2
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all the
time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
Hello there
Is there a way through dotNet to check if a certain user is a member of a
specific group?
I use ADSI to get the memberships of the user then compare them to the
group I want to check, but this way the user has to be a member of this
group directly and if he is a member of a group that is a member of that
group he will not be considered a member of the group I am checking
although he is implicitly.
so basically what I need is a method that takes the user name and the
group name and check if this user is a member both implicitly or
explicitly.
Any ideas?
Regards
Sameh


Nov 21 '05 #3
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all the
time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
Hello there
Is there a way through dotNet to check if a certain user is a member of
a specific group?
I use ADSI to get the memberships of the user then compare them to the
group I want to check, but this way the user has to be a member of this
group directly and if he is a member of a group that is a member of that
group he will not be considered a member of the group I am checking
although he is implicitly.
so basically what I need is a method that takes the user name and the
group name and check if this user is a member both implicitly or
explicitly.
Any ideas?
Regards
Sameh



Nov 21 '05 #4
I am on a local administrator on a stand alone machine, did not try it in a
domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all
the time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
Hello there
Is there a way through dotNet to check if a certain user is a member of
a specific group?
I use ADSI to get the memberships of the user then compare them to the
group I want to check, but this way the user has to be a member of this
group directly and if he is a member of a group that is a member of
that group he will not be considered a member of the group I am
checking although he is implicitly.
so basically what I need is a method that takes the user name and the
group name and check if this user is a member both implicitly or
explicitly.
Any ideas?
Regards
Sameh



Nov 21 '05 #5
AppDomain myDomain = Thread.GetDomain();

myDomain.SetPrincipalPolicy(PrincipalPolicy.Window sPrincipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;

bool isUser = wp.IsInRole("BUILTIN\\Users");

bool isDBA = wp.IsInRole("MACHINENAME\\ORA_DBA");
On my machine, with the code above, both IsInRole calls return true.

The code is basically copied directly out of the MSDN library
WindowsPrincipal.IsInRole() documentation.

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am on a local administrator on a stand alone machine, did not try it in a
domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all
the time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
> Hello there
> Is there a way through dotNet to check if a certain user is a member
> of a specific group?
> I use ADSI to get the memberships of the user then compare them to the
> group I want to check, but this way the user has to be a member of
> this group directly and if he is a member of a group that is a member
> of that group he will not be considered a member of the group I am
> checking although he is implicitly.
> so basically what I need is a method that takes the user name and the
> group name and check if this user is a member both implicitly or
> explicitly.
> Any ideas?
> Regards
> Sameh
>
>



Nov 21 '05 #6
Whoops. I hadn't even realized I had clicked into the vb group for this
thread. If you can't translate the C# to vb, set the code filter in your
MSDN to vb and it should be pretty easy to figure out.

DalePres
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
AppDomain myDomain = Thread.GetDomain();

myDomain.SetPrincipalPolicy(PrincipalPolicy.Window sPrincipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;

bool isUser = wp.IsInRole("BUILTIN\\Users");

bool isDBA = wp.IsInRole("MACHINENAME\\ORA_DBA");
On my machine, with the code above, both IsInRole calls return true.

The code is basically copied directly out of the MSDN library
WindowsPrincipal.IsInRole() documentation.

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am on a local administrator on a stand alone machine, did not try it in
a domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all
the time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
> Look up the IPrincipal.IsInRole() method. You would use the
> WindowsPrincipal implementation for WindowsForms or the
> User.IsInRole() implementation for WebForms.
>
> DalePres
> MCAD, MCDBA, MCSE
>
> "Sameh Ahmed" <es******@hotmail.com> wrote in message
> news:uj**************@TK2MSFTNGP09.phx.gbl...
>> Hello there
>> Is there a way through dotNet to check if a certain user is a member
>> of a specific group?
>> I use ADSI to get the memberships of the user then compare them to
>> the group I want to check, but this way the user has to be a member
>> of this group directly and if he is a member of a group that is a
>> member of that group he will not be considered a member of the group
>> I am checking although he is implicitly.
>> so basically what I need is a method that takes the user name and the
>> group name and check if this user is a member both implicitly or
>> explicitly.
>> Any ideas?
>> Regards
>> Sameh
>>
>>
>
>



Nov 21 '05 #7
Just out of curiosity, what version of .NET are you using? Early versions
of 1.0 had a bug where IsInRole was case sensitive.

The other thing I'd suggest is using reflection to troubleshoot the problem
by accessing the private _GetRoles method on WindowsIdentity. A quick
Google search should turn up some sample code that shows you how to do it.

http://groups-beta.google.com/group/...5ce5f46ae876a6

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am on a local administrator on a stand alone machine, did not try it in a
domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all
the time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
Look up the IPrincipal.IsInRole() method. You would use the
WindowsPrincipal implementation for WindowsForms or the User.IsInRole()
implementation for WebForms.

DalePres
MCAD, MCDBA, MCSE

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
> Hello there
> Is there a way through dotNet to check if a certain user is a member
> of a specific group?
> I use ADSI to get the memberships of the user then compare them to the
> group I want to check, but this way the user has to be a member of
> this group directly and if he is a member of a group that is a member
> of that group he will not be considered a member of the group I am
> checking although he is implicitly.
> so basically what I need is a method that takes the user name and the
> group name and check if this user is a member both implicitly or
> explicitly.
> Any ideas?
> Regards
> Sameh
>
>



Nov 21 '05 #8
I tried it today in an AD environment and it worked just fine.
Not on local machines though!
thanks everybody for your time.
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
Whoops. I hadn't even realized I had clicked into the vb group for this
thread. If you can't translate the C# to vb, set the code filter in your
MSDN to vb and it should be pretty easy to figure out.

DalePres
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
AppDomain myDomain = Thread.GetDomain();

myDomain.SetPrincipalPolicy(PrincipalPolicy.Window sPrincipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;

bool isUser = wp.IsInRole("BUILTIN\\Users");

bool isDBA = wp.IsInRole("MACHINENAME\\ORA_DBA");
On my machine, with the code above, both IsInRole calls return true.

The code is basically copied directly out of the MSDN library
WindowsPrincipal.IsInRole() documentation.

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am on a local administrator on a stand alone machine, did not try it in
a domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have
been logged in as a local machine user, rather than as a domain user. I
don't know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Well I use IsInRole to check windows built-in Roles
> what I want to do is to check if the current principal is a member of
> a local group called "Mygroup" for example.
> below is what I got from the MSDN
> [Visual Basic]
> Overloads Public Overridable Function IsInRole( _
> ByVal role As String _
> ) As Boolean Implements IPrincipal.IsInRole
>
> I tried "machinename\groupname", "groupname" and it returns False all
> the time.
> what am I missing here?
> Regards and thanks for your time
> Sameh
>
>
> "DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
> news:e2**************@TK2MSFTNGP15.phx.gbl...
>> Look up the IPrincipal.IsInRole() method. You would use the
>> WindowsPrincipal implementation for WindowsForms or the
>> User.IsInRole() implementation for WebForms.
>>
>> DalePres
>> MCAD, MCDBA, MCSE
>>
>> "Sameh Ahmed" <es******@hotmail.com> wrote in message
>> news:uj**************@TK2MSFTNGP09.phx.gbl...
>>> Hello there
>>> Is there a way through dotNet to check if a certain user is a member
>>> of a specific group?
>>> I use ADSI to get the memberships of the user then compare them to
>>> the group I want to check, but this way the user has to be a member
>>> of this group directly and if he is a member of a group that is a
>>> member of that group he will not be considered a member of the group
>>> I am checking although he is implicitly.
>>> so basically what I need is a method that takes the user name and
>>> the group name and check if this user is a member both implicitly or
>>> explicitly.
>>> Any ideas?
>>> Regards
>>> Sameh
>>>
>>>
>>
>>
>
>



Nov 21 '05 #9
Joe
the usual thank you:)

"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:uI**************@TK2MSFTNGP15.phx.gbl...
Just out of curiosity, what version of .NET are you using? Early versions
of 1.0 had a bug where IsInRole was case sensitive.

The other thing I'd suggest is using reflection to troubleshoot the
problem by accessing the private _GetRoles method on WindowsIdentity. A
quick Google search should turn up some sample code that shows you how to
do it.

http://groups-beta.google.com/group/...5ce5f46ae876a6

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am on a local administrator on a stand alone machine, did not try it in
a domain environment.
how do you format the group name in your code?
Regards
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:O0*************@TK2MSFTNGP09.phx.gbl...
I have only gotten IsInRole to work against local groups when I have been
logged in as a local machine user, rather than as a domain user. I don't
know if that is by design or a bug (feature).

HTH

DalePres
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Well I use IsInRole to check windows built-in Roles
what I want to do is to check if the current principal is a member of a
local group called "Mygroup" for example.
below is what I got from the MSDN
[Visual Basic]
Overloads Public Overridable Function IsInRole( _
ByVal role As String _
) As Boolean Implements IPrincipal.IsInRole

I tried "machinename\groupname", "groupname" and it returns False all
the time.
what am I missing here?
Regards and thanks for your time
Sameh
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
> Look up the IPrincipal.IsInRole() method. You would use the
> WindowsPrincipal implementation for WindowsForms or the
> User.IsInRole() implementation for WebForms.
>
> DalePres
> MCAD, MCDBA, MCSE
>
> "Sameh Ahmed" <es******@hotmail.com> wrote in message
> news:uj**************@TK2MSFTNGP09.phx.gbl...
>> Hello there
>> Is there a way through dotNet to check if a certain user is a member
>> of a specific group?
>> I use ADSI to get the memberships of the user then compare them to
>> the group I want to check, but this way the user has to be a member
>> of this group directly and if he is a member of a group that is a
>> member of that group he will not be considered a member of the group
>> I am checking although he is implicitly.
>> so basically what I need is a method that takes the user name and the
>> group name and check if this user is a member both implicitly or
>> explicitly.
>> Any ideas?
>> Regards
>> Sameh
>>
>>
>
>



Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Shyguy | last post by:
I have an option group with about 30 options. I would like to have the Option Labels get their text from a table. Is this possible, and if so how? Also, is it possible to embad a font into a...
0
by: Vinny Vinn | last post by:
I am writing a C#/asp.net app.I have a requirement to check if the user is member of specific Domain group,how can this be accomplished? I tried the following and it always returns false ,even if...
3
by: Chad Beckner | last post by:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't...
1
by: Matt | last post by:
I am wanting to make a login for my VB app. Basically what I want to do is have a user enter their username and click "Login". The program then binds to the user object in AD. Then it checks to see...
7
by: Sameh Ahmed | last post by:
Hello there IsInrole gives ya the means to check if the current or impersonated user belongs to a specific windows role or group. is there a way to do the same without using ADSI to check if...
12
by: Ryan | last post by:
Is there anyway to enable spell-checking for user input in a Text Box? Either auto spell-check or create a spell-check button. Using VB 2005.
3
by: tomlebold | last post by:
When using Access security can each group have only one password? So all members of the group have the same and/or one password? Then in order to have each member of a group have their own password...
1
by: Tony WONG | last post by:
i can use Request.ServerVariables to check the login user. is it possible to check whether the login user is the member of the NT security group? it is because i wish to create a dynamic...
2
by: newVBNETuser | last post by:
I want to get the follow vbScript to work in VB.NET Set objRun = CreateObject("wscript.Shell") strUserName = objRun.ExpandEnvironmentStrings("%USERNAME%") Dim strComputer, member, strUsername,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.