To “open” or NULL, that is the verb

When you programmatically want to execute a shell item/path/URI you are forced to pick a verb even when you want to perform the default action (A.K.A. double click). This means passing NULL as the verb if you are calling ShellExecute[Ex]. When you do this the shell will do its magic to find the default verb:

  1. Use the verb the user has set as the default.
  2. If there is no default, use open.
  3. If there is no open verb, use the first verb returned by RegEnumKey

Hard-coding open as the verb is a very common mistake and doing that will ignore the users default action if they have made any changes to the verbs for that file-type/URL protocol:
Folder options: Edit verbs

This dialog was removed in Vista but you can still edit the registry manually.

Incredibly the start menu “Search the Internet” feature (AddSearchInternetLinkInStartMenu policy) gets it both right and wrong!

To get the icon Explorer (Explorer!­GetDefaultBrowserNameAndIconIndex) uses the Shell32!­CAssocArray object to Init with "HTTP" as the ProgId and then correctly calls GetString­( ASSOCF_VERIFY,­ ASSOCSTR_EXECUTABLE,­ … ) with pwszExtra set to NULL.
However, when it is time to launch the browser Explorer (Explorer!­_InvokeDefaultBrowserSearch) calls AssocQueryStringW­( 0,­ ASSOCSTR_EXECUTABLE,­ L"HTTP",­ L"open",­ ... ) and forcing "open" can actually make ASSOCSTR_EXECUTABLE return the wrong .exe if the user has changed the default verb! (It is actually documented that it determines the default browser this way)

Tags: ,

One Response to “To “open” or NULL, that is the verb”

  1. Jop (@com2BOY) Says:

    Hey why are you using windows while you hate it so much?
    Why not use Linux?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.