0

How would I go about elevating my running C# program only when necessary?

I come from Java and I see programs like IntelliJ only calling on their "elevator.exe" when a task requires administrator privileges.

So, I am wondering how I would go about doing the same thing in C#, only elevating the current program when a task needs elevating (for example, an update), and then being able to run the specified task. It wouldn't bother me if I too had to make my own "elevator.exe", I would just like to know how it is done so that I may recreate it.

I'm not trying to just run another program with administrator privileges, I want to give admin access to the current program, to perform operations like updates, like IntelliJ does.

Corentin Pane
  • 4,345
  • 1
  • 10
  • 27
Ark1409
  • 25
  • 6
  • 1
    Welcome to c# and stackoverflow, is the answer you seek in this link? https://stackoverflow.com/a/32938785/8306962 – Joel Nov 07 '19 at 06:04
  • Doesn't the link above lead to a comment about F#, instead of C#? And no, that is not what I mean. I do not want it to automatically start with admin privileges, I only want the app to request admin privileges when necessary (like if the app must make a folder in sys32) – Ark1409 Nov 07 '19 at 06:07
  • sorry, I hotlinked to the wrong answer, the accepted answer in that thread should perhaps be of some help. – Joel Nov 07 '19 at 06:10
  • Oh okay sorry, I will have another look. – Joel Nov 07 '19 at 06:11
  • 1
    Perhaps this thread has what you are looking for? https://stackoverflow.com/a/2021878/8306962 – Joel Nov 07 '19 at 06:12
  • I get System.Security.SecurityException: 'Request for principal permission failed.' – Ark1409 Nov 07 '19 at 06:19
  • EDIT: Wait. I think i might understand now. Thanks for the info. (I'll still leave this question open because I don't think i fully understand) – Ark1409 Nov 07 '19 at 06:26
  • But how would you restart the host program (as in, relaunch application) from the "updater.exe"? – Ark1409 Nov 07 '19 at 06:28

0 Answers0