user3161924
user3161924

Reputation: 2317

IContextMenu Handler - Should ShellExecute or CreateProcess be used to InvokeCommand?

I've added a handler for the context menu in explorer to show items conditionally. My question is now when it comes time to InvokeCommand should I use ShellExecute to run the .exe that needs to run, or should I use the CreateProcess()method?

Basically the way Windows would do it with static entries is what I'd like to duplicate.

TIA!!

Upvotes: 1

Views: 78

Answers (1)

Anders
Anders

Reputation: 101756

ShellExecute can do two things CreateProcess cannot:

  1. Launch files other than .exe and .cmd/.bat.
  2. UAC elevate applications marked as RequireAdministrator/Highest in their manifest.

CreateProcess can set some advanced options for the child process that ShellExecute cannot (handle inheritance, debugging and the attribute list).

If you don't know what you are launching, ShellExecute is generally preferred. The one thing you have to be careful of is that you don't execute yourself when using ShellExecuteEx (causing an infinite loop). Not setting the SEE_MASK_INVOKEIDLIST flag will reduce the risk of this happening. If you know you are launching a .exe then this will not happen...

Upvotes: 1

Related Questions