[英]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. 我希望能够从我的程序中注册我的文件扩展名。 (Associate the filetype with my program)
(将文件类型与我的程序关联)
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. 有很多关于此的文章,但据我所知,所讨论的技术(摆弄注册表)仅适用于Windows XP。
What is the best way to associate a filetype with a program so that it works under XP, Vista and Windows 7 as well ? 将文件类型与程序关联以使其在XP,Vista和Windows 7下运行的最佳方法是什么? (Are there any working code-examples ?)
(有没有工作代码示例?)
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. ClickOnce是一个选项,但这只在安装时注册文件类型,而我希望能够在运行时注册文件类型。
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. 在Windows Vista(可能是Windows 7)中,文件关联已更改:如果文件已与程序关联并重新关联,则双击该文件将无法使用新程序打开它。 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中注册关联应用程序的小讨论(Web Archive,原始链接已不复存在)。
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.
我不知道它在Vista +上是否有所不同。
If you need to add file association in a non admin scenario, you can use User-specific file associations which is described in this article . 如果需要在非管理方案中添加文件关联,则可以使用本文中介绍的特定于用户的文件关联。 Check out the " User-specific file associations ".
查看“ 用户特定的文件关联 ”。
There were only a couple changes from XP to Vista/7 as far as file association goes, so most examples for XP should still work. 就文件关联而言,从XP到Vista / 7只有一些变化,所以XP的大多数例子仍然有效。 The only think you should be concerned about is the 'Default Programs' setting in Vista/7 that did't exist in XP and overrides other file association registration.
唯一认为你应该关注的是Vista / 7中的“默认程序”设置在XP中不存在并覆盖其他文件关联注册。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.