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

Users

How can I find out if the current user is the administrator of the os?
Thank you
Nov 16 '05 #1
5 1032
Alberto,

First, you will have to get the current windows user identity. You can
do this by calling the static GetCurrent method on the WindowsIdentity
class. Then, pass that WindowsIdentity instance to the constructor of a
WindowsPrincipal class. With that, you can call the IsInRole method and
pass the Administrators role (a string), or you can pass in the
Administrator value from the WindowsBuiltInRole enumeration.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Alberto" <al*****@nospam.es> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
How can I find out if the current user is the administrator of the os?
Thank you

Nov 16 '05 #2
Watch for word wrap but this should do it:

WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
if (myPrincipal.IsInRole(WindowsBuiltInRole.Administr ator))
{
...
}

Have A Better One!

John M Deal, MCP
Necessity Software

Alberto wrote:
How can I find out if the current user is the administrator of the os?
Thank you

Nov 16 '05 #3
One thing to note here is that if you do use the string parameter option
(as opposed to the enum) you need to actually pass
"BUILTIN\Administrators" or it will not recognize it. This is true for
all of the roles in the WindowsBuiltInRole. I mention this because it
had me going for a bit when I needed it and thought I could just pass
the "Administrators" in. Just thought I'd mention it.

Have A Better One!

John M Deal, MCP
Necessity Software

Nicholas Paldino [.NET/C# MVP] wrote:
Alberto,

First, you will have to get the current windows user identity. You can
do this by calling the static GetCurrent method on the WindowsIdentity
class. Then, pass that WindowsIdentity instance to the constructor of a
WindowsPrincipal class. With that, you can call the IsInRole method and
pass the Administrators role (a string), or you can pass in the
Administrator value from the WindowsBuiltInRole enumeration.

Hope this helps.

Nov 16 '05 #4
While you could use the CurrentPrincipal on the thread, it's not
guaranteed that it will always return a WindowsPrincipal, so you have to
watch out for it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John M Deal" <jo******@necessitysoftware.com> wrote in message
news:Od**************@TK2MSFTNGP14.phx.gbl...
Watch for word wrap but this should do it:

WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
if (myPrincipal.IsInRole(WindowsBuiltInRole.Administr ator))
{
...
}

Have A Better One!

John M Deal, MCP
Necessity Software

Alberto wrote:
How can I find out if the current user is the administrator of the os?
Thank you

Nov 16 '05 #5
Good point, I got the code I posted out of the MSDN documentation. This
is the line I use in my code when I do this kind of thing:

WindowsPrincipal wp = new
WindowsPrincipal(System.Security.Principal.Windows Identity.GetCurrent());

I'm pretty sure this one is solid (but let me know if I'm wrong about
it, thanks).

John Deal, MCP
Necessity Software

Nicholas Paldino [.NET/C# MVP] wrote:
While you could use the CurrentPrincipal on the thread, it's not
guaranteed that it will always return a WindowsPrincipal, so you have to
watch out for it.

Nov 16 '05 #6

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

Similar topics

4
by: zsh-users-help | last post by:
Hi! This is the ezmlm program. I'm managing the zsh-users@sunsite.dk mailing list. To confirm that you would like python-list@python.org removed from the zsh-users mailing list, please send...
6
by: Hannu | last post by:
Hi. In the ldb file you can see the users of the mdb-file. If you open the mdb-file your machine and username will be written in the lbd- file. Allthough you close the mdb-file your name won't...
5
by: Andy Davis | last post by:
I have a two tables, Users and Requests, the latter which displays the daily log on's of 20 users. Both tables are related by a one-to-many relationship in the Requests table via the UserId field....
3
by: mgPA | last post by:
Short: How can I limit the number of concurrent logins to Access (2000) DB? Long: I seem to be having the problem discussed in previous postings of having more than 9 or 10 concurrent logins. ...
6
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by...
6
by: google | last post by:
I have a few general questions. I am working on a new database to be used within my company. I would like to give a couple of people, particularly HR, the ability to add and delete Access users,...
5
by: profdotnet | last post by:
Below is the code of web.config file: <configuration> <system.web> <authentication mode="Forms" /> <authorization> <allow users="Admin"/> <deny users="Jack,Mary" /> <deny users="?">...
1
by: cefrancke | last post by:
I have a Back End database (split) that is on a smokin' hot machine (dual processor, 2 gig RAM, XP Pro SP2) and I'm getting an error that says the database (back end file) is "opened exclusively"...
2
by: Vayse | last post by:
1) How do I get a list of all users in a domain? I've searched the web, but any sample I've found seems to use VB 2003 or earlier. Is there any samples that user 2005, and make full use of the My...
9
by: Jonathan Wood | last post by:
I've spent days trying to come up with a solution. I'd appreciate it if anyone can help. My site requires all users to log on. There are three different roles of users, and each user type will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.