Search code examples
c++windows-7windows-vistauacshellexecute

Open default browser as standard user (C++)


I'm currently using ShellExecute "open" to open a URL in the user's browser, but running into a bit of trouble in Win7 and Vista because the program runs elevated as a service.

When ShellExecute opens the browser, it seems to read the "Local Admin" profile instead of the user's. So for example, if the user at the keyboard has Firefox as his default browser, it may open IE (which is the admin's default).

I know that the "runas" verb can be used to elevate, but how do you do it the other way around? Is there a way to open a URL in the default browser on a standard user's desktop from a service?


Solution

  • ShellExecute will execute the program in the context of the same session and same user as the process you are running.

    If you'd like to use a different session or user token you can use the CreateProcessAsUser Win32 API.

    There are several ways to obtain a user token, for example you can call the Win32 API: