Search code examples
.netvb.netuacwindows-authentication

Authenticate as administrator?


I'm developing an installer, and I would like to write to a folder accessible only to administrators. So, I need to display the UAC dialog and authenticate as an administrator. I know I could do this by having a separate executable that I run from the installer GUI, but I'd rather a solution that allows me to authenticate whenever I want in the application. Is this possible in .NET?


Solution

  • You can not change privilege level mid process, once a process has started it is stuck at that privilege level. You must launch a separate process with elevated privileges and communicate with it with IPC to update the GUI.

    If you are writing a installer the best thing is to just mark the installers own application manifest as administrative rights itself so it will request admin privileges when it starts as you will need it every time anyway.