When I run my c# Windows Forms Application on Windows 7 with:
- A user in the "Users" group that is not in the Administrators group
- On a machine where User Account Control is turned off
- By right-clicking the EXE and selecting "Run as Administrator"
This code:
WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCu开发者_开发技巧rrent());
bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);
still returns false. Is this expected behaviour?
I am pretty sure if the user is not an Administrator, Run As Administrator is not going to elevate that user's context for that application to that of Administrator. That would be a terrible security hole and end-run around enforced security of keeping users as normal users.
精彩评论