Require your application to run with administrator privilages

Sometimes your application requires to run with administrator rights. For example to access some restricted resources on a computer. Within .Net we can adjust our application in such a way, the user is asked to run the application with elevated administrator rights. In this way the application is executed with administrator rights, hence has less restrictions. Downside of this is that also more harm can be done with bad written code (think of erasing all files on the harddrive of a user).

Go to your project that requires the administrator previlages. Add “Application Manifest File” to the project. By default Visual Studio will apply the just added manifest file to your project properties.

Make sure in the app.manifest file the following items occur:

<security>
     <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">        
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
   </requestedPrivileges>
</security>

When the application is now started, it will request to start with granted administrator rights.

Posted in C# by Bruno at February 9th, 2016.

Leave a Reply