Self-Elevating App

Say What?aaaaaaa

Yes: My Brain wrote a Self-Elevating App.

I have been writing a Windows Application (32-bit x86 executable) in Visual Studio 2010, that uses the HKEY_LOCAL_MACHINE/Software/AppName registry key to save some basic settings. After some strange accesss errors I figured out that you need administrative access to actually be able to do this. I run Windows 7 with UAC turned to 0, so no problem there. However running the same App in Windows 8, it will not be started as administrator by default. Sure, you can right-click the icon or executable and select ‘run as administrator’, but that’s a pain.

The solution is simple; In your project properties (remember “Assembly Information” to set the next version number), click “View Windows Settings” to open your App.Manifest. Look for the following line and change the “asInvoker” value:

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

Next compile, build, publish, whatever… and your app will run as administrator on the machine, so you can access that registry. Of course, the logged-in user must have the required rights, otherwise it will still be a no-go.