Sergey Kolesnik
Sergey Kolesnik

Reputation: 3630

Explicit ShellExecute without elevated rights

ShellExecute has a parameter that allows to request a UAC permission to run a process with elevated rights: runas

Launches an application as Administrator. User Account Control (UAC) will prompt the user for consent to run the application elevated or enter the credentials of an administrator account used to run the application.

But is it possible to do the contrary?
I have an application that is run with elevated rights by default and there are urls which user can open. But if I use ShellExecute, a default browser will be opened. Some malware can be registered as a default browser.


using CreateProcessAsUser to launch a url - this question seems to be on the same problem. It generally indicates, that CreateProcessAsUser can't be used to open a URL by itself.

Upvotes: 1

Views: 587

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490018

My personal inclination would be to call FindExecutable or AssocQueryString, then use CreateProcessAsUser to open the browser with the un-elevated account/credentials.

This is a little more work than using ShellExecute, but not a whole lot--and it makes your intent 100% clear and explicit.

Using COM from C++ is enough work that it's almost certainly more work to use IShellDispatch2, and (at least to me) that seems likely to do quite a bit more to hide the real intent of the code.

Upvotes: 1

Related Questions