Wednesday 1 June 2011

.Net Application runs with administrator rights

Sometimes it happens that when we run our C# .Net application on Windows Vista, Windows 7 machine or Windows Server 2008 it do not run properly and throw exceptions related to file or directory access rights. However, when we run that application by right clicking on its exe and selecting Run as Administrator. It runs properly without any access right issues.

We can handle it programmatically in .Net application as following 
  • Add Application Menifest file (if not added previously) in the project. It can be done by right clicking on ProjectàAddàNew Item->Application Menifest File.
  • Change the <requestedExecutionLevel> element to:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />    

The user gets the UAC prompt when he starts the program. Use wisely, his patience can wear out quickly.

No comments:

Post a Comment