You have probably noticed that with windows 8 when you disable UAC it doesn’t fully turn off. You are able to completely turn it off but that then disables the ability to use any of the Modern UI applications. So today I dug a bit and eventually managed to get a solution to make your application run as admin when being run from a click once deploy.
The way a user would be able to enable admin mode for a regular application is to Right click on the application and click ‘Run as administrator’
With click once applications you aren’t able to do this. I suppose you could find one of the many ways to locate the actual executable and then run as administrator but then every time the application updates you will need to locate the application again and also many users (including myself) won’t see this as a suitable way to launch an application as administrator.
After trying all the regular methods of enabling an application to run as full administrator I eventually got to the solution below.
Add these usings into the program.cs file
Add the member and method to the program.cs class
Add the parameter string args to the main method if it does not already exist
And finally wrap all the code inside you main method with
That’s all you need to be able to run your application as administrator on launch. Basically what is going to happen is your application will start up and see that there is no command argument for –engage, it will then get it’s own executable path and attempt to run itself again using administrator mode. If a user has UAC enabled they will be prompted as usual to allow the application to run in admin mode and if they have UAC disable in windows 8 the application will now run if real administrator mode.