tags:

views:

448

answers:

1

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.GetCurrent()); bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);

still returns false. Is this expected behaviour?

+2  A: 

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.

Jesse C. Slicer
Why is it a security hole? (assuming that the user has to enter an administrator password)
Matthew Wilson
Well yes definitely. But it is surprising that there is no message to the user at this point?
Duncan Edwards
@Matthew: The user DOESN'T have to enter an administrator password. What you really want is the "Run As User" command and have you app run under the user context of an administrator.@Duncan: Unfortunate: yes. Surprising: I think the jury's out on that! :)
Jesse C. Slicer