Giving application elevated UAC

Solution 1:

You don't need to meddle with all that to make sure that your application always runs with elevated privileges. You can simply add an application manifest which instructs Windows to run your app elevated, and the UAC prompt will appear without you needing to write a single line of code.

There's a related question with an answer that also describes how to add a manifest here: How can I embed an application manifest into an application using VS2008?

Solution 2:

Elevating your privileges is always going to start a new process. There is no way around that, other than starting with elevated privileges in the first place by setting your application to require administrative privileges. What you can do is end the application right after the elevated process starts, so that you only have one application running.

This scenario is usable for applications that only require certain parts of their function to be elevated - such as an automatically self-updating installer that needs access to Program Files - and not one that requires administrative access all the time.

Solution 3:

This is a much better approach when your application is known to require Admin privileges from the start.