如何以编程方式创建可在XP,Vista和Windows 7中使用的文件关联 [英] How to programmatically create a file association that works in XP, Vista and Windows 7

查看:71
本文介绍了如何以编程方式创建可在XP,Vista和Windows 7中使用的文件关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从我的程序中注册我的文件扩展名.(将文件类型与我的程序相关联)

I want to be able to register my file-extension from my program. (Associate the filetype with my program)

关于此的文章很多,但是据我所知,讨论的技术(摆弄注册表)仅适用于Windows XP.

There are lots of articles about this, but the technique discussed (fiddling with the registry) is only appropriate for Windows XP as far as I see.

将文件类型与程序相关联以使其在XP,Vista和Windows 7下也能正常运行的最佳方法是什么?(是否有任何有效的代码示例?)

What is the best way to associate a filetype with a program so that it works under XP, Vista and Windows 7 as well ? (Are there any working code-examples ?)

ClickOnce是一个选项,但这仅在安装时注册文件类型,而我希望能够在运行时注册文件类型.

ClickOnce would be an option, but this only registers the filetype at installation-time while I want to be able to register filetypes at runtime.

推荐答案

在Windows Vista(可能是Windows 7)中,文件关联已更改:如果文件已与程序关联,而您将其重新关联,则双击该文件将不会.用新程序打开它.而是将关联添加到打开方式"下的列表中.另请参见

In Windows Vista (and presumably Windows 7) file associations have changed: if a file is already associated with a program and you reassociate it, doubleclicking the file won't open it with the new program. Instead, the association is added to the list under "open with". Also see this little discussion on registering your application for associations in Vista (Web Archive, original link is gone).

我不确定更改此设置是否合适.但是,这篇文章讨论了您可以使用注册表中的各种键.但更好的是,此代码项目文章使您可以随时使用代码来关联文件在运行时.我不知道它在Vista +上是否有任何不同.

I'm not sure whether it is good to change this. However, this post discusses the various keys in the registry that you can use. But even better, this codeproject article gives you ready to use code for associating a file at runtime. I don't know whether it works any differently on Vista+ though.

这篇关于如何以编程方式创建可在XP,Vista和Windows 7中使用的文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆