Sep 222012
 

With the changes to the UAC system in Windows 8, it seems that whenever you try to launch an non-elevated application from an elevated application, you get an error similar to: “Class not registered (Exception from HRESULT: 0×80040154 (REGDB_E_CLASSNOTREG)”.

The reason is that under Windows 8, even if you set UAC to the lowest setting, you don’t disable it completely.

In my case, I was trying to start an URL using the default browser from an elevated application. After a lot of digging around on stackoverflow.com and other blogs and websites, I’ve managed to build a solution that seems to be working.

The solution relies on the UacHelper class from this stackoverflow post: http://stackoverflow.com/a/4497572/940730.

The code checks if UAC is enabled and if you are running under an elevated account. If this is the case, instead of passing the URL directly (which leads to an error), it starts explorer.exe with the URL as the argument. The “runas” verb is an undocumented verb which basically makes the process run under administrative privileges:

A more complete alternative is provided also by the UAC Helpers project on CodePlex: http://uachelpers.codeplex.com/, but the library is at the moment only in alpha stage (although I believe that it should work properly). The biggest downside is that the library is done in C++/CLR so for me this was a roadblock.

 Opening an URL in the default browser on Windows 8