How do I accept files to be opened via IDropTarget instead of on the command line? – bonus content


One of my colleagues tipped me off to some additional resources on the subject of using the DropTarget technique for accepting files for execution.

First, it turns out that there is an SDK sample that demonstrates the DropTarget technique after all. This sample is fifteen years late according to one commenter who apparently thinks that the Platform SDK needs to provide a sample for a feature that won't be invented for another twelve years. Maybe we can use the Microsoft Research project to predict the future. No wait, we also need to get them to invent the time machine so we can take the future-predictor machine back in time 15 years.

Second, there is a sample for the ExecuteCommand technique. The ExecuteCommand technique is preferred over the DropTarget technique because it is much easier to implement. (Translation: much less you can get wrong.) Like the DropTarget technique, the ExecuteCommand supports out-of-process activation.

And third, as it turns out, App Path registration supports HKEY_CURRENT_USER after all, thereby addressing one of the complaints raised by a commenter (a complaint I answered incorrectly).

Comments (17)
  1. WndSks says:

    The claim that HKCU supports App Paths key is simply not true (On XP, not sure about Vista/7, but we all know Vista RTM really lacked in the HKCU/COM department) See img571.imageshack.us/…/nocuapppaths.png

    [Try reading past the first ten words in the link I provided, sucker. -Raymond]
  2. Anonymous says:

    Re: Time machine

    It wouldn't help. Most theories limit time travel to the time the machine was invented at the earliest.

    [Then they'll just have to work on a new theory, too! -Raymond]
  3. Anonymous says:

    @Raymond: It is not clear from the Application Registration page that HKCU is 7+ only since the whole "Using the App Paths Subkey" part only talks about 7 and no other versions. Just before that section under "Registering Applications" it talks about XP:SP1 and that App Paths is the preferred location, but it never talks about which HKEY it must be under (And the App Paths key has existed much longer than that (Win95?), and has certainly been the preferred way to modify the per app %path% for way longer than just XP).

    The only clear statement about HKEY's is a comment in the DropTargetVerb sample: "// Windows7 supports per user App Paths, downlevel requires HKLM" (Maybe you could get that added to the MSDN page)

    I know the MS focus is mostly on current+next versions, but most of us need to target XP and maybe 2000 for a while longer. The sad part is that HKCU support should have been added when DropTarget was added, not 3 versions later (When I'm done building this time machine, I'll get right on that)

  4. Anonymous says:

    @WndSks

    Quoth the linked article: "To register an application with the App Paths subkey in Windows 7 and later"

    Seems pretty clear to me that it's Windows 7 and later.

  5. Anonymous says:

    ‘it turns out that there is an SDK sample that demonstrates the DropTarget technique after all’ – If it's any consolation, I liked the OTN article better.

    I must say I had to do a double take on the App Paths thing, and I have to thank WndSks for clearing this up. Raymond should have known that it's probably a good idea to mention any dependency on Windows 6+.

    On that note, ExecuteCommand needs Windows 6.1, so most of us can't use it, something which should have been mentioned in the article.

  6. Anonymous says:

    Boris:  Most theories also preclude the possibility of traveling backward in time, so it *really* wouldn't help.

  7. Anonymous says:

    AppPath… CURRENT_USER… Hmm… Nice feature… I wonder if I override a path for a system component with some "custom" stuff silently dropped into temporary files…

  8. Leo Davidson says:

    @Kemp, I think WndSks's point there was that the App Paths subkey is *not* only for Windows 7 and later. (Look on an XP machine and you'll find loads of App Path entries created before Windows 7 even existed, at least in HKLM.)

    When the article says something about "Windows 7 and later" you cannot assume anything about earlier versions. In fact, much of the information applies to them as well.

    (I can say, in London people breathe air. You'd be wrong to infer that people do otherwise outside of London. :))

    Having said all that, XP not supporting HKCU App Paths (if that's the case) doesn't seem like a big deal to me. App Paths registry entries are useful but not essential; per-user installs aren't something I'm fond of (though there are exceptions); in the rare cases you need that stuff to be per-user there were decent-enough workarounds.

    PS: FWIW, the article also has the registry paths wrong at the start of the quoted section. It uses "…MicrosoftCurrentVersion…" when the real path is "…MicrosoftWindowsCurrentVersion…" (It's a very common path, though, and it gets it right just below there, so I don't imagine it'll cause many people problems).

  9. Anonymous says:

    @Leo Davidson: The App Paths for HKLM is supported on XP. But the question was why it wasn't also available for HKCU, becuase you need admin priviledges for that part of HKLM, which can trigger a UAC popup.

    Raymond's right – that link is accuate for Windows 7 and later.

    The unspecified behavior, and a problem in the document is it doesn't describe previous versions of Windows. But as it is, it's clear in Windows 7, all users use HKLM, current user use HKCU.

    In Vista and below, it's not documented. We know empirically that HKCU does NOT work and HKLM does. But that should be noted – perhaps by using the "Notify Microsoft" link or adding it as community content.

  10. Anonymous says:

    @Alexandre:

    AppPath is searched last, so good luck with that.

  11. Anonymous says:

    (Totally OT, but can't resist)

    @Leo: Are you sure people in London breathe air, and not smog? :) Although maybe congestion tax has actually solved that problem.

  12. Anonymous says:

    [Try reading past the first ten words in the link I provided, sucker. -Raymond]

    "Sucker"…oaw….this is the 1st reply of Ray that I see he's using somehow vulgar word to insult his commenter…in the past he did it with sarcasm or more subtle irony by providing counter arguments but now was just a vulgar word. Regress.

    Who are you and what you did with Ray?

  13. WndSks says:

    @Danny: Some people might say I'm asking for it (And a snarky reply is better than nothing)

  14. Anonymous says:

    @Danny: It's the new blog engine style. I like it too! You might feel it's regression, but this is a blog, for educational purposes only; it's not corporate communication. I personally think Raymond's been trying to cater too much to some of his audience. His will to stay "politically correct" has turned at times to what looked like frustration. I'd personally rather have him vent like that!

  15. Anonymous says:

    The moral of the story imho is to always keep older versions of MSDN around.  No vendor with as many products as Microsoft can maintain every version of the documentation so they naturally tend to disappear off the web over time.

    I still keep a copy of Oct 2001 MSDN for just such occasions….

  16. Anonymous says:

    The link is far from clear – it indicates that there's something specific to 7, sure, but it could be read as meaning any of: that HKCU is only supported on 7 whereas HKLM is supported on all versions [the correct answer]; that the entire App Paths feature is new in 7; or even that HKLM is only supported on 7 whereas HKCU is supported on all versions. The correct answer is in fact a less obvious interpretation of the text (absent the knowledge of what worked on XP) than either of the other two.

    Also, the "Finding an Application Executable" section was not updated mention HKCU at all, which also means it doesn't say which one is searched first.

  17. Anonymous says:

    The link is far from clear – it indicates that there's something specific to 7, sure, but it could be read as meaning any of: HKCU is only supported on 7 whereas HKLM is supported on all versions [the correct answer]; the entire App Paths feature is new in 7; or HKLM is only supported on 7 whereas HKCU is supported on all versions. The correct answer is in fact a less obvious interpretation of the text (absent the knowledge of what worked on XP) than either of the other two.

    Also, the "Finding an Application Executable" section was not updated mention HKCU at all, which also means it doesn't say which one is searched first.

Comments are closed.