.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

check if user belongs to a windows group C#

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :.NET Framework
Hello Guys, I have eneed to check if the current windows user is part of a specific windows group say corp\BO. I tried using isinRole but it returns false no matter what.
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); 
bool result = wp.IsInRole(@"corp\BO_ops"); 
is there another way of doing this? pls let me know.  I'm stuck with this and could not proceed.

View Complete Post

More Related Resource Links

How to check effective permissions for a user or group for a SQL server object or whole server?

Guys, How do I see effective permissions for a user or group for a SQL server object or whole server? For example, a user is not listed in security/logins, but he is a member of few groups and some of them have assigned permissions on SQL server (again either directly or through membership in other groups) Even when I select an object (a table), check properties/permission – it doesn’t let me select any principal, except those listed on security/logins… Anyway, what is the right way to see effective permissions for a user or group? Sorry for asking such a simple question, I’ve searched but found nothing relevant.

check user exists in which group

After entering user name, i want check user belonging to which group, group is some thing like role based if group is something group1 , then i want redirect hime to page 1, if groupis 2  then page 2 like that

"NT Authority\SYSTEM" is member of Windows Administrators group? How to check it?

I have workgroup Windows XP Pro SP3 with SQL Server 2008 R2 I have read the answer of Satya SKJ in Purpose of "NT AUTHORITY\SYSTEM" login in SQL Server 2005 topic in this forum (*): "Local System account. The name of this account is NT AUTHORITY\System. It is a powerful account that has unrestricted access to all local system resources. It is a member of the Windows Administrators group on the local computer, and is therefore a member of the SQL Server sysadmin fixed server role" Why do not I see "NT Authority\SYSTEM" as a member of Administrators group in my computer (compmgmt.msc ---> System Tools --< Local Users and Groups --> Groups --> administrators)? I see there only  Administrator. How to check and manage the membership of "NT Authority\SYSTEM" (as well as of "NT Authority\Network Service" and "NT Authority\Local Service") in Windows? (*) Update: Now, I found the same phrase it in MS SQL Server 2008 R2 BOL [1] Cited: http://msdn.microsoft.com/en-us/library/ms191543.aspx Selecting an Account for the SQL Server Agent Service (SQL Server 2008 R2)   

SQL 2005: Error 15401 - Windows NT user or **group** not found


I have a fresh install of Windows Server 2008 R2 x64 Standard Edition and SQL Server 2005 x64 on top of that, with Service Pack 3. This server, SERV, is in DOMAINA which trusts (one-way) DOMAINB.

When I try to create a login for a group in my domain, I get the following error:
Msg 15401, Level 11, State 1, Procedure sp_grantlogin, Line 49
Windows NT user or group 'DOMAINA\groupname' not found. Check the name again.

I get the same error whether using "create login [domaina\groupname] from widnows", "sp_grantlogin [domaina\groupname]" or Manangement Studio.
This happens ONLY for groups , both in DOMAINA and DOMAINB domains. I can add individual users from both A and B and local computer. For local computer groups: I can add default Windows groups (like Users, Guests, Event Log Readers) by [BUILTIN\Event Log Readers], etc. but not by SERV\Event Log Readers; for custom created group MyLocal it's the other way around: I can via SERV\MyLocal but not via BUILTIN\MyLocal.

If I add a domain group from either DOMAINA or DOMAINB to a local group, whether my own or builtin, I can login to SQL Server remotely using creditentials of a user who belongs to that group (user DOMAINB\ux belongs to DOMAINB\group and DOMAINB\group to SERV\MyLocal). After sp_grantlogin [serv\mylocal] of cours

How to check user is a particular group


How to check user is related to a particular group , if he is assigned to multiple groups

Error 15404 - Could not obtain information about Windows NT group/user 'Dev\Administrator', error


SQL Server 2008 R2 with the latest CU floods event log with "An exception occurred while enqueueing a message in the target queue. Error: 15404, State: 19. Could not obtain information about Windows NT group/user 'Dev\Administrator', error code 0x54b".

Domain controller is located on the same server (Win 2008 R2), this is SharePoint virtual machine. There are no DNS or Directory Service errors.

How can I troubleshoot this?


SPView query to find if the current user belongs to a Group


HI All,

I´m trying to write a query for a list view that should return all items if the current user belong to a group. If the user doesn´t belongs to this group, no items should be returned.

So far, I could find many equal examples about using the CAML Membership element in a comparison with an AssignetTo field. But not making a comparison between the current user and a specific Sharepoint Group.

Any suggestions, please?


Getting the Group Name User Belongs to Error


Hi all,

I have the following AD Strucure

Domain Controller with the Name like abc.com ........> Groups Folder .....>>>UserGroups >>> Subgroup >>>> List of Users

I did the following but not succeed

 string GetADUserGroups(string userName)
            DirectorySearcher search = new DirectorySearcher();
            search.Filter = "(&(objectClass=user)(SAMAccountName=" + userName + "))";
           // search.Filter = String.Format("(cn={0})", userName); "(&(objectClass=user)(cn={0}))",  userName
            StringBuilder groupsList = new StringBuilder();
            SearchResult result = search.FindOne();
           if (result != null)
                int groupCount = result.Properties["memberOf"].Count;
                for (int counter = 0; counter < groupCount; counter++)
             return groupsList.ToString();


Iam getting the Count == 0 at the below line

int group

Sql 2008 on Windows 2008 domain error: windows nt user or group not found

I am running sql 2008 R2 and win 2008 R2 and simply trying to add a new domain user into sql, but I get the error above. What's weird is that when I do a check names from the add user or group window it finds the account I want to use. I've tried adding a different account, but I get the same issue--so its not the account. I've also tried running the create login t-sql command but it gives the same error. I've also tried disabling, via the gpedit.msc tool, the digitally encrypt or sign secure channel keys. But that did not work either.

CAML query to check if user is member of a specific group


I've got a nested query caml which basically should check 3 things:

  1. Check if a task has been assigned directly to the ucrrent user
  2. Check if a task has been assigned to a group the user is in
  3. Check if the user is member of a specific

The first to bullet points work like a charm, but I can't figure out how to get the last one to work. Here is what I thought should work:

query += "<Where>";
query += "<Eq><Membership Type=\"CurrentUserGroups\">";
query += "<Value Type=\"String\">Name of my specific group</Value>";
query += "</Membership></Eq>";
query += "</Where>";

Somehow it doesn't seem to be the correct approach, is there somebody who can help me out on this? Thanks

Could not obtain information about Windows NT group/user '' - Error



when i am trying to  run Create  Assembly scipt i am getting follwing  Error...

 Could not obtain information about Windows NT group/user [DOMAIN\user].

Pleas help me on this ?


No ASPNET User in Windows Server 2008?


I have been looking everywhere online regarding this, but have not found a clear answer.


I have an ASP.Net app running on Windows Server 2008, it's basically a reporting app using Crystal Reports. I have encountered a roadblock in regards to rendering some pages. When I run the app in Visual Studio(on the same 2008 machine) everything works perfectly. Yet when I publish it and run it live the reports will not display correctly, I get a message saying Failed to render page.


I looked this error up in the Crystal Reports website and the fixes they have there refer to giving the windows "aspnet" user full access rights to certain folders on the machine. I would be happy to do this, however there is no aspnet user in Windows Server 2008.


I installed the server and set its role to be Web Server. I also checked all the options regarding ASP.Net and IIS 6 compatibility. Yet there is no ASPNET username anywhere.


Did I set the server up wrong? or do I have to do something within ASP.Net to  create this user and then give it rights? 

Least Privilege: Teach Your Apps To Play Nicely With Windows Vista User Account Control


User Account Control in Windows Vista keeps the OS safe from intentional and accidental configuration changes.

Chris Corio

MSDN Magazine January 2007

App Fundamentals: Build A Great User Experience With Windows Presentation Foundation


The Windows Presentation Foundation application model distinguishes between standalone and browser applications and between menu driven and hyperlink driven navigation, resulting in a more satisfying experience for your users.

Michael Weinhardt

MSDN Magazine October 2006

Windows Forms: Developing Compelling User Controls that Target Forms in the .NET Framework


In the beginning, writing controls meant dealing with Windows messages. Then came Visual Basic controls, which introduced methods, properties, and events. Later, ActiveX controls, which ran atop COM, became popular. While each innovation in control writing brought more flexibility, nothing has matched the versatility of the new .NET Windows Forms controls and Web Forms controls. This article, the first of a two-part series, introduces the reader to Windows Forms, beginning with their inheritance from one of the .NET CLR base classes, which makes control creation much faster than before. Control programming is illustrated through the development of a login control. The equally flexible Web Forms controls will be covered in Part 2.

David S. Platt

MSDN Magazine April 2002

Windows 2000 UI Innovations: Enhance Your User's Experience with New Infotip and Icon Overlay Shell


Windows 2000 includes some helpful new UI features you can customize and implement in your own applications. In this article you'll see how to provide infotips for files, after making the appropriate registry entries. Then create a custom column handler extension, resulting in a new column for the Explorer's Details view. In order to further extend the shell, additional UI goodies will also be examined and implemented including: search handlers, cleanup handlers, folder customizations using property sheet handlers and icon overlays, and context menu shell extensions. All the code samples are rolled up into a handy package which we've named, by tradition, ShellToys.

Dino Esposito

MSDN Magazine March 2000

Forms based users being prompted for windows authentication login for My Sites photos in user lists

Here's an issue I didn't see coming for our forms based authentication users. 

We have a web application extended to an external url to handle forms based authentication for users outside of our domain. Our setup looks like this...

Internal Users/Windows Authentication - moss.domain.com
External Users/Forms Based - mossext.domain.com
My Site for Internal Users - mysites.domain.com

When our forms based users are accessing user lists, or discussion pages that display user pictures, they are getting a windows authentication login for our internal users (mysites.domain.com) who have populated their my site with personal photo.

How do we fix this? 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend