Restart program unelevated

后端 未结 2 699
后悔当初
后悔当初 2021-01-05 06:22

For some reason, my C# program needs to restart with elevated privileges. I use the following code to achieve it:

private static void RestartForPermissionsFi         


        
2条回答
  •  梦谈多话
    2021-01-05 06:49

    I had the same problem with an application that I wanted to update automatically (The update program requires elevated privileges).

    What I did was creating an external .exe that would start my updater program with elevated privileges, wait for it to exit, then restart my application with normal privileges.

    I then embedded this .exe in my main application, and start this .exe just before leaving my application when I update it.

提交回复
热议问题