Create UAC Compatible applications in .NET
In my last project I got an opportunity to make my application compatible with Windows Vista and Windows 7. The main issue I faced was UAC; User Account Control (UAC) which introduced with the launch of Windows Vista; this provides users a better and safer computing experience. If UAC enabled, Windows will prompt every time when Applications try to access File System, like writing / creating Files in Program Files Folder, Windows Folder etc. (It’s not a best practice to write / create files in System directories like Windows, Program Files etc.). It’s also not a best practice to ask the customer to disable the UAC and run the application. The alternate is to make the application compatible with UAC, so that when the customer runs the application the system will prompts the UAC dialog, and run the application with Administrator privileges.
The procedure to make the application compatible with UAC is simple.
- Right-click project and add a new item.
- From the Add New Item box select Application Manifest File.
- In the manifest file un-comment the following line:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Build your application. And when the build is complete you will see the security shield icon accompanying your application icon.
A dialogue box appears in front of the user to run the application with full administrative privileges.
