ShellExecute fails if run from elevated process an

2019-02-06 19:26发布

问题:

Set non-default browser in Windows 8 RTM (Chrome, Firefox) and try to run code like this:

ShellExecute(NULL, "open", "http://stackoverflow.com", NULL, NULL, SW_SHOWNORMAL);

It's ok. But then change manifest to require Administrative priveleges or just "run as administrator".

Code won't work.

Ok, then try to run any application using "run as administrator".

You will see the same result, links are not working.

Change default browser back to IE -> all works fine.

In Windows 8 previous builds there is no such behavour.

What is going on?

PS. It seems Microsoft experienced the same problems in their own software :) Visual Studio 2012 Web Publish on Windows 8 RTM Fails Browser Launch

回答1:

I've been seeing the same behavior with Chrome until today. Spent some time trying to figure out what was going on and couldn't for the longest time make Chrome come up with ShellExecute() under elevated rights either. Failed for elevated rights (ie. UAC dialog, or Run As Administrator) or even when turning off UAC altogether.

I ended up uninstalling and re-installing Chrome and that actually fixed it.

Also saw the behavior with other browsers, however after a few tries with FireFox I went into the Set Default Programs settings from FireFox and EXPLICITLY (ie. in Windows) set the associations for .htm file and the HTTP protocol. That worked as well.

So it looks like this is some sort of registration issue, rather than an actual problem in Windows. First thing I would try is to explicitly set the associations in Windows (rather than Set Default Browser in the browser). If that fails try reinstalling the browser...



回答2:

@ Rick Strahl

You're incorrect. It's not just registration. I tested with Photoshop CC and Windows 8. I created a launcher for Photoshop to make it portable: - with Administrative Rights, shell integration does not work. - when run as normal user, shell integration works as expected.

Tested on Windows 7. - works with or without Administrative Rights.

I can confirm O.P. is correct.