The default verb is not necessarily "open"


If you hunt around the Internet you’ll find lots of people† who hard-code the string "open" as the second parameter to the ShellExecute function, indicating that they want to open the document specified as the third parameter. While that’s a nice thing to want to do, it might not be the right thing.

When the user double-clicks a document, the shell executes the default verb, which is not necessarily “open”. For example, for audio files, the default verb is often “play”, and for pictures, it’s often “view”. If you want to launch the document as if the user had double-clicked it, then you need to pass NULL as the lpOperation.

Commenter brad asked how the default verb is determined. This is explained in MSDN in the section titled, not surprisingly, Verbs and File Associations:

The primary verb is specified by the default value of the shell key, or the open key if the shell key has no default value. … The primary verb is also referred to as the default verb.

Nitpicker’s corner

†The phrase “lots of people” means “lots of people”. It doesn’t mean “lots of people not including Microsoft.”

Comments (19)
  1. Adam says:

    OK, but why have "play" or "view" in place of "open"? Why not just have "open"? It means the same thing. What’s the semantic different between opening a word document, opening a PDF, opening an image, opening a movie, and opening a sound recording?

    Why pick a non-"standard" verb to do something when the standard one would work just as well?

  2. S says:

    I’d much rather ‘Play’ a song than ‘Open’ it. As for PDF files, ‘Open’ to me implies open for edit, whereas ‘View’ implies a read-only view.

    I always get caught out by .cmd scripts – I’d much rather have a ‘Run’ default verb for these.

  3. James says:

    Responding to Adam and expanding on what S wrote, "play" and "view" are, of course, more descriptive than "open"; and "open" is ambiguous. ("Open" for what purpose? To edit? To play or view?)

    This seems like enough justification to use a "non-standard verb"–because the standard verb won’t work just as well.

    As a generally corollary: "Why do X when Y would be just as good?" is a common question, often used (as in this case) to claim that doing X was a mistake. But it is often the case (as it is here) that the correct answer to the question is, rather, "Y would not be just as good." When you observe someone doing something that you don’t understand, it’s possible that they do know what they’re doing.

  4. MarkW says:

    The reason the default action isn’t always ‘Open’ is because that’s not very clear to the user. For images, I see ‘Preview’ and ‘Edit’. I haven’t a clue which the ‘Open’ verb is connected to, actually.

    And with .reg files, the default action is Merge. I’m not sure what the Open command does, but it’s quite likely to open (for editing) in Notepad rather than merging the .reg file. Not a good user experience if their program opens a file with a bunch of registry keys for them to look at!

    By the way, is there any way for me to tell what Open does in Vista? Other than checking the registry, of course. I just don’t see advanced application association anymore…

  5. Adam says:

    Sorry – I had a brain fart and forgot that these values are shown to users.

    (Which then makes me wonder how they’re localizable properly if you’ve got two users with different locales on the same computer, but I suspect that’s getting a bit OT)

  6. swautier says:

    The "displayed name" of a verb can be renamed. On my (XP) box, JPEG files’s default verb is "open" but it displays as "Pre&view" (MUI supported). See MUIVerb value under Shell.

    Therefore objections to Adam’s point of view don’t seem valid IMHO.

  7. Roland Rabien says:

    And sometimes there is no "open" verb, and then nothing will happen. This was a bug in my app.

  8. S says:

    swautier: Good point – I was vaguely assuming that verb always equalled displayed name of the verb. That’s what comes of replying between compiles.

  9. Nar says:

    I’d much rather ‘Play’ a song than ‘Open’ it. As for PDF files, ‘Open’ to me implies open for edit, whereas ‘View’ implies a read-only view.

    So, then, we’ve got "view", "edit", and "execute"; the question is "Why have the non-standard ‘play’ instead of ‘view’?".

  10. zachd says:

    the question is "Why have the non-standard ‘play’ instead of ‘view’?".

    View also has specific connotations – perhaps the user wants to View the metadata or waveform or etc.  Play would thus be more appropriate, especially for an audio file.

    Historically in the multimedia world, Play meant Play Immediately.  Open meant Open this file, but do not play it.  I believe that changed around Windows Media Player 7.

  11. Dean Harding says:

    So, then, we’ve got "view", "edit", and "execute"; the

    question is "Why have the non-standard ‘play’ instead of ‘view’?".

    Whoever heard of "view"ing a sound file?

    What does it matter whether it’s "open" or "view" or "play" anyway? The point is, if you want the default, pass in NULL. If you want the user to select, enumerate the verbs and display them all.

  12. Weiguo says:

    it’s not necessarily just a question of semantics (where "open" really means "play", all of the time).  HTML docs you might want to open/view (in a browser), or open/edit (in Notepad, etc.).  Batch files you might want to run, or, if you’re like me, you change the default action to opening them in Notepad.

  13. Leo Davidson says:

    Why do any of you care what the default verb is called when you can execute it by not giving a verb?

    Or, put another way, there already is a default verb: NULL.

    Seems to me that everyone wants ShellExecute to work in the incorrect way they’ve been using it (so that "open" always executes the default action) instead of changing the way they are using it to the correct method (passing NULL for the verb if you want the default).

  14. Leo Davidson says:

    Very good point, Weiguo. Users should be free to change which verb is the default — to change what happens when they double-click files — without having to change the meanings of the verbs themselves, since that could break other programs which legitimately call a specific verb.

  15. Norman Diamond says:

    Thank you (mostly) for the nitpicker’s corner.  Even though your anger is apparent, the meaning behind it really does help (mostly).  Just please keep in mind that in many cases your readers have more reasons for anger than you do.  Please recall

    http://blogs.msdn.com/oldnewthing/archive/2007/03/14/1878777.aspx

    It doesn’t mean "lots of people not including

    Microsoft."

    Alternative wording:  It includes Microsoft.

  16. Jules says:

    “Why do any of you care what the default verb is called when you can execute it by not giving a verb?”

    Because the default can be changed.  For instance, out of the
    box, I believe the default action for a .html file is “open”, whereas
    on my machine it’s “edit”.  I find it particularly annoying when a
    program then produces an HTML report and launches it in my text editor,
    because it should have been written to use the “open” action which is
    guaranteed to do what it wants. [1] Programs _should_ be hard coding
    what action to perform on the file if there is a particular action that
    should be performed, rather than just a nebulous “do whatever the user
    normally wants to do with this type of file” concept.

    [1]: This is, however, a step better than the programs which launch
    IE despite the fact I have HTML files ‘open’ action associated with
    Firefox.

    [I find it interesting that you actually want a program to override your custom default action. -Raymond]
  17. Thomas says:

    Hardcoding it to "open" still doesn’t ensure that it will always open in a web browser.  On one of my machines, "open" on HTML files results in the file opening in VIM.  This is probably a more common situation than "edit" being the default action, as windows makes it easier to change file associations than default actions.  If you want a file to always open in a certain type of program, you have to hardcode in the program to be run, which causes all the problems with IE opening when you wanted FF.

  18. KJK::Hyperion says:

    You can change the default verb so that you can register associations for "shared" file types to your application without conflicting with the existing ones. Except a file type in Windows is really meant as a "document type", i.e. the data for a specific application, and not a "content type", so what the usual offenders (see: media players, office suites) often do is just pointing the extension to a different filetype altogether

    Funny thing is, urlmon does add all the code and registry data to link document types to content types (among which even a database of content type signatures, or "magic numbers"), but it’s only used by Internet Explorer, not by the shell except indirectly when opening content through an URL, so it might as well not be there at all

    People might say Internet Explorer is too integrated with the shell, I say it isn’t integrated enough, not when an URL scheme needs to be registered in three different places to actually work everywhere (why not register URL handlers as regular monikers, instead of the HKCRPROTOCOLS, mk: URL scheme etc. mess?)

    I guess Apple did handle this kind of mess better with Uniform Type Identifiers

Comments are closed.