473,396 Members | 1,784 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,396 software developers and data experts.

Determining if the user has admin privileges

Hi,
I'm writing a C# .NET code in which I need to first determine if the
user has administrative privlieges on that system (or if the user belongs to
the administrative group). Could anyone please tell me how I can achieve this.

Thank you

Ravi.
Aug 5 '05 #1
2 2081
You need to use the WindowsPrinciple class in the System.Security.Principal
namespace.

e.g.
=====================
using System.Security.Principal;
using System.Threading;

....
....

Thread.GetDomain().SetPrincipalPolicy(PrincipalPol icy.WindowsPrincipal);
WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;
bool isAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);
Console.WriteLine(isAdmin);
=====================

The above code will print out "True" if the current user is an Administrator
and "False" if not;

Hope this helps!

Brian Delahunty
Ireland

http://briandela.com/blog
"Ravi" wrote:
Hi,
I'm writing a C# .NET code in which I need to first determine if the
user has administrative privlieges on that system (or if the user belongs to
the administrative group). Could anyone please tell me how I can achieve this.

Thank you

Ravi.

Aug 5 '05 #2
Hi Brian,
Thanks for the quick reply to my question. Your suggestion is
very helpful to me at this time.

Thank you

Ravi.
"Brian Delahunty" wrote:
You need to use the WindowsPrinciple class in the System.Security.Principal
namespace.

e.g.
=====================
using System.Security.Principal;
using System.Threading;

...
...

Thread.GetDomain().SetPrincipalPolicy(PrincipalPol icy.WindowsPrincipal);
WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;
bool isAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);
Console.WriteLine(isAdmin);
=====================

The above code will print out "True" if the current user is an Administrator
and "False" if not;

Hope this helps!

Brian Delahunty
Ireland

http://briandela.com/blog
"Ravi" wrote:
Hi,
I'm writing a C# .NET code in which I need to first determine if the
user has administrative privlieges on that system (or if the user belongs to
the administrative group). Could anyone please tell me how I can achieve this.

Thank you

Ravi.

Aug 5 '05 #3

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

Similar topics

3
by: MLH | last post by:
I was running the following code while logged in as a user belonging only to the Users group. Set usrNew = .CreateUser(Me!UserID) 'The user ID is in a control on the form usrNew.PID =...
0
by: Chandra | last post by:
Hi I developed the installation by using Installshield Devstudio 9 with Installscript MSI project type Now I am using "Run As" dialog to install an applicaiton on XP operating system for admin...
2
by: Ravi | last post by:
Hi, I'm writing a C# .NET code in which I need to first determine if the user has administrative privlieges on that system (or if the user belongs to the administrative group). Could anyone please...
11
by: AnhTai | last post by:
Hi all, I've just installed MySQL 5.0 on my sun box (runing Solaris 10, install from blastwave). This is my first time with MySQL so I don't have any exp with it. I have some troubles as: -...
0
by: nemo | last post by:
Hi, I'm able to create, debug, and run ASP.Net projects when I login as a user with admin privileges. However if I logon to the same machine as a user without admin privileges, I get the...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
4
by: Don Calloway | last post by:
I'm attempting to implement User-level security on an Access 2003 database in Access 2000 format and have hit a brick wall. I created a Workgroup Information File with myself as admin and added...
2
by: gangac | last post by:
I am currently working on an ms access application for a large insurance company which generates reports for the user after the user inputs/select some data.... Unfortunately the application has...
11
by: giddy | last post by:
hi, (I want someone to check if my idea is utterly stupid or ok??) I have a mid complex app for a hotel that needs a fine grained user security system. In other words an admin should be able...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.