472,780 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 2057
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.