471,344 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 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 1997
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by AnhTai | last post: by
33 posts views Thread by JamesB | last post: by
4 posts views Thread by Don Calloway | last post: by

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.