How to run an elevated privilege ("as administrator") app on Windows startup

Running an elevated application at startup time on Windows 8 is rather annoying. Normally, the easiest way to run anything at startup is to simply create a shortcut to it in %AppData%\Microsoft\Windows\Start Menu\Programs\Startup. Unfortunately when UAC is on, Windows will simply refuse to launch any shortcut at startup time if its properties are configured to run the application to which it points as administrator. In Windows 7 and below, disabling UAC let everything work just fine. Windows 8 changes matters by requiring UAC to be enabled in order for the Metro app sandbox to function - in other words, disabling UAC kills all Metro apps. You can still silence UAC (I do) but it's no longer reasonable to disable it.

There are multiple ways to get around this restriction, such as using the Task Scheduler to launch the app as a startup task or writing a Windows service to launch the app. However, the most straightforward way is still to use the Startup directory. The big difference is, instead of calling a shortcut, execute a script!

In my case, I want to launch the OpenVPN GUI. It needs elevated privileges in order to control its virtual network interface. Instead of creating a shortcut, I created a new file named OpenVPN.vbs in the Startup directory with the following two lines:

Set UAC = CreateObject("Shell.Application")  
UAC.ShellExecute "C:\Program Files\OpenVPN\bin\openvpn-gui.exe", "", "", "runas", 1

That script launches the OpenVPN GUI with elevated privileges. Simply replace the first parameter for ShellExecute with whatever app you're trying to launch and you're good to go! And if you need to pass command-line arguments, that's what the second parameter is for.

 
comments powered by Disqus