Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force my .NET application to run as administrator?

Once my program is installed on a client machine, how do I force my program to run as an administrator on Windows 7?

like image 539
Gold Avatar asked May 12 '10 11:05

Gold


People also ask

How do I force an app to run as administrator?

Again, right-click on the app's name. Click on Properties and select the Shortcut tab. Select Advanced. Finally, mark the checkbox next to Run as administrator.

How do I always run Visual Studio as administrator?

On the Windows desktop, right-click the Visual Studio shortcut, and then select Properties. Select the Advanced button, and then select the Run as administrator check box. Select OK, and then select OK again.


1 Answers

You'll want to modify the manifest that gets embedded in the program. This works on Visual Studio 2008 and higher: Project + Add New Item, select "Application Manifest File". Change the <requestedExecutionLevel> element to:

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 

The user gets the UAC prompt when they start the program. Use wisely; their patience can wear out quickly.

like image 185
Hans Passant Avatar answered Oct 07 '22 17:10

Hans Passant