Recently, an acquaintance noticed that FindExecutable doesn't always work, in particular with certain 5-letter file extensions. He needed a way to find the associated executable for these, and another acquaintance suggested using the AssocQueryString API. It wasn't one I was very familiar with, but I quickly became so when I took a look at the sorts of information it can provide. Here's an example of what this sample gives you for any given extension / verb combination:

The core of this project is a drop-in ready class you can just instantiate and pass the desired extension to. The CAssociations class uses "open" as the default verb, but you can provide anything you'd like. It's actually a very nice way to determine whether a verb, like "print", is supported at all.

One problem with AssocQueryString is that on older operating systems (NT4, 98, 95), it isn't available unless Internet Explorer 5 (or higher) is installed. The class automatically tests for this, to avoid triggering an error, by looking to see if the function is exported from the shwapi dynamic link library.


This sample, or the one from which it originally derived, was published (or at least peripherally mentioned) in the following article(s):

APIs Usage

This sample uses the following API calls:

Module Library Function
CAssociations.cls kernel32


Don't see what you're looking for? Here's a complete API cross-reference.


Download   Please, enjoy and learn from this sample. Include its code within your own projects, if you wish. But, in order to insure only the most recent code is available to all, I ask that you don't share the sample by any form of mass distribution.

Download, 6Kb, Last Updated: Thursday, September 24, 2009

See Also

The following resources may also be of interest: