0

I need the program I'm making to request admin privileges. If the user denies the pop up message the program will continue but some features will be missing.

I have tried putting the code below in the app.manifest file but when the user denies the program privileges the program does not start.

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
  • 1
    http://stackoverflow.com/q/2271656/57508 –  Dec 19 '14 at 09:30
  • The old question is not the same! – i486 Dec 19 '14 at 09:33
  • @i486 I am aware of this, as I did not mark the question as a duplicate. My referenced question is just about "all or nothing" part and the fact that the application determines its elevation-need itself. –  Dec 19 '14 at 09:35
  • Ok, but this question is now closed and cannot post answers. You had to post only a comment. – i486 Dec 19 '14 at 09:36
  • @i486 As I did. It was PatrickHofman who closed this question, but I have nominated the question for reopening! Anyway, there's another method: You could attribute the methods with `[SecurityPermissionAttribute(SecurityAction.RequestMinimum, Assertion = true)]` and use a `try`/`catch` around the calls. –  Dec 19 '14 at 09:37
  • @i486: Okay. Misunderstood the question I guess. Next time, please ping me, then I will notice it quicker. – Patrick Hofman Dec 19 '14 at 09:43

2 Answers2

0

There's no way to do this. By the time your program is running, it's too late - you either have admin privileges or you don't. If you don't, the only way to get those admin privileges is to restart the application as admin.

Chris
  • 4,661
  • 1
  • 23
  • 25
0

The app must restart itself with ProcessStartInfo Verb = "RunAs". Then close current instance (non-admin).

i486
  • 6,491
  • 4
  • 24
  • 41