User Privileges

  • Thread starter Thread starter Feldman Alex
  • Start date Start date
F

Feldman Alex

Hi all,



I need to know the user privileges (does user have administrator privileges)
..

Which c# api's should i use?

Thanks a lot
 
Feldman Alex said:
Hi all,



I need to know the user privileges (does user have administrator
privileges)
.

Which c# api's should i use?

Thanks a lot
Please define Administrator privileges.
If a user is a member of the administrators group it has the same privileges
as the administrator suposing administrator is also a member, but that
doesn't mean a lot if someone changed the default administrator privileges.

What privilege are you looking for exactly?

Willy.
 
Well , I'll describe a full task.
I'm writing a install application, and I need to know that the user have the
privileges to install/write to program files.

Thank you
Alex
 
Feldman Alex said:
Well , I'll describe a full task.
I'm writing a install application, and I need to know that the user have
the
privileges to install/write to program files.

Thank you
Alex


By default only administrators and power users have write access privileges
to "Program Files", so you could also check group membership for the current
user.
Something like this should do...
AppDomain ad = Thread.GetDomain();
ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal user = (WindowsPrincipal)Thread.CurrentPrincipal;
if(user.IsInRole(WindowsBuiltInRole.Administrator) ||
user.IsInRole(WindowsBuiltInRole.Administrator))
{
// Ok, user is power user or administrator
..
}
else
// Non privileged user, not ok to continue...

Another way to determine the access privileges to a folder, is by creating a
dummy file into the folder, if it fails, it's because the user has no write
access privileges.

Willy.
 
Thank you Willy
You helped me a lot :)

Willy Denoyette said:
By default only administrators and power users have write access privileges
to "Program Files", so you could also check group membership for the current
user.
Something like this should do...
AppDomain ad = Thread.GetDomain();
ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal user = (WindowsPrincipal)Thread.CurrentPrincipal;
if(user.IsInRole(WindowsBuiltInRole.Administrator) ||
user.IsInRole(WindowsBuiltInRole.Administrator))
{
// Ok, user is power user or administrator
..
}
else
// Non privileged user, not ok to continue...

Another way to determine the access privileges to a folder, is by creating a
dummy file into the folder, if it fails, it's because the user has no write
access privileges.

Willy.
 
Back
Top