On Tue, 17 Jul 2007 00:50:03 -0700, windsim
<wi*****@discussions.microsoft.comwrote:
Hi,
I have a C# program that need to know whether the user that run the
application is administrative user or limited user.
Are there any methods in C# I can use?
Since you already got an answer to the actual question, I will offer this:
Why do you think you need to know whether the user is an administrator or
not?
I have run into applications that do this sort of check, and they always
wind up confounding my attempts to maintain a secure system. They are
generally written wrong in the first place, insisting on having access to
areas of my computer that they don't need access to for normal operation,
and by checking my user type explicitly, they negate any attempt on my
part to provide narrowly-defined access to the specific resources they
want without exposing the rest of my computer to the application.
IMHO, there are at least two different ways you can address the usual
things related to admin/limited user rights:
1) Simply try to access to resource and see if it succeeds or fails.
IMHO, this is the best, as it allows complete flexibility on the part of
the user with respect to managing how the application runs. They can
provide the necessary access as necessary, and/or take advantage of
Vista's virtualization features to allow the application to run.
2) Check the user credentials for the resource directly (see "access
control list"). This may defeat attempts by the user to allow
virtualization of the resource, but at least the user can still open
access to the specific resource your application requires without having
the application demand full administrator rights when it doesn't really
need them.
In either case, of course, it is imperative that you provide a useful
error message to the user so that they know what resource it is your
application is trying to access, so that they can change the security
settings as necessary.
Even better, of course, would be to fix your application so that it
doesn't matter whether an admin or limited user is running the application.
Pete