1

Having used the code posted here to launch a web page after uninstall, I note that ShellExec starts the browser with the elevated credentials used by default by the Programs and Features control panel when starting the uninstaller.

Using ShellExecAsOriginalUser is documented as not possible during uninstall, and the suggestion made here does not seem to be applicable in the case of wanting to access a URL.

Any suggestions on how to handle this?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    FWIW, I find this behavior to be annoying. (I don't want a web page to open automatically when I uninstall something.) – Bill_Stewart Aug 28 '20 at 14:56
  • @Bill_Stewart Same here. Some applications show a popup window with multiple choice that atleast gives you control of being taken to a website. – Andrew Truckle Aug 31 '20 at 10:05

1 Answers1

1

Based on How to run exe with/without elevated privileges from PowerShell, this seem to do the trick:

Exec('explorer', 'https://www.example.com/', '', SW_SHOW, ewNoWait, ErrorCode);

I believe it works, because while the code obviously runs explorer process elevated, the Explorer does not allow multiple instances. So the new instance will just ask the existing instance of explorer (which is not elevated) to open the URL. The existing non-elevated instance of Explorer will run non-elevated instance of the web browser.

It's similar to how the web browsers themselves work. If you run chrome url (or any other browser) from an elevated process (like the un/installer), if no Chrome process is running yet, the URL opens in new elevated Chrome browser. But if some Chrome process is already running, the new elevated process will just ask the existing non-elevated process to open the URL.

The only difference is that while there is not always some web browser process running, there is always an (unelevated) Explorer process. And actually, even if there's not, Explorer de-elevates itself.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992