Finding the default application for a particular file name extension (Even when served by a metro app)

152 views Asked by At

How do I find the default application for a particular file extension?

This seems to vary depending on the version of windows, however the best option I have found seems to be using AssocQueryString in shlwapi, which seems to work quite well for some types of applications.

However, it fails in windows 8, probably because the default pdf viewer there is a metro "App".

The reason I want to know is so that I can launch the default application for a given file if there is a default application. - Otherwise, I am happy to give a message saying: "The file has been generated but you have no viewer installed to display it."

1

There are 1 answers

0
Arafangion On

Answer was to use os.startfile (in python), which seems to be equivalent to ShellExecute (and ShellExecuteEx), although with a simplified interface.

try:
    os.startfile(r'abspath/to/file', 'open)
except WindowsError:
    os.startfile(r'abspath/to', 'open') # Fallback to opening directory.

Credits to Jonathan and David, who suggested that the original approach of finding the application path isn't feasible anymore with metro-apps. As it turns out, the application path isn't super important anyway.