How to programmatically create a file association that works in XP, Vista, and Windows 7

I want to be able to register my file extension from my program. (Link the file to my program)

There are many articles about this, but the technique discussed (messing with the registry) is only suitable for Windows XP, as far as I know.

What is the best way to associate a file type with a program so that it works in XP, Vista, and Windows 7? (Are there any working code examples?)

ClickOnce will be an option, but it only registers the file type at installation time, while I want to be able to register file types at runtime.

+6
c # windows-7 windows-xp windows-vista file-association
source share
3 answers

In Windows Vista (and presumably Windows 7), file associations have changed: if the file is already associated with the program and you re-link it, double-clicking the file will not open it with the new program. Instead, the association is added to the list under "open with". Also see this short discussion of registering your association application in Vista (web archive, original link gone).

I'm not sure if this is good to change. However, this post discusses various registry keys that you can use. But even better, this code article gives you the ability to use code to link a file at runtime. I don't know if it works differently on Vista +.

+6
source share

If you need to add file associations to a non admin script, you can use custom file associations that are described in this article . Check user file associations .

+1
source share

There were only a few changes from XP to Vista / 7, as file association is coming, so most XP examples should work anyway. The only thing that bothers you is the "Standard Programs" option in Vista / 7, which does not exist in XP and overrides another registration of file associations.

0
source share

All Articles