If you need to force a .NET Application to run with Administrative Privileges, you simply need to modify the Application Manifest File of your Project. If you need Help Adding a Application Manifest File to your Project, see this post: Adding a Manifest Application File to your Visual Studio Project.
You only need to change:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
If you have the User Access Control (UAC) enabled, the user gets prompted when starting the program.
When using ClickOnce, it is possible that you recieve the following error when compiling your application with the updated manifest file.
ClickOnce does not support the request execution level requireAdministrator.
If so, check the Enable ClickOnce security settings Option under the Security tab.
Removing this option should let you compile your application, but keep in mind that the MSDN says that you cannot use ClickOnce when you need administrative privileges to run.
However, if you really need to use ClickOnce and forced Administrative Privileges, you should have a look at this awesome blogpost‘s: Charles Engelke’s Blogpost about Click-once, administrative access, and code signing , followed by Anthony’s Blogpost about Running a ClickOnce Application as Administrator and in addition for facing the ApplicationDeployment.IsNetworkDeployed = false problem this Comment by Mark.
If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.
Related links: Adding a Manifest Application File to your Visual Studio Project, Application Manifests, Charles Engelke, Anthony, Mark