如何以编程方式创建适用于 XP、Vista 和 Windows 7 的文件关联
我希望能够从我的程序注册我的文件扩展名。 (将文件类型与我的程序相关联)
有很多关于此的文章,但据我所知,所讨论的技术(摆弄注册表)仅适用于 Windows XP。
将文件类型与程序关联起来使其在 XP、Vista 和 Windows 7 下也能运行的最佳方法是什么? (有任何有效的代码示例吗?)
ClickOnce 是一个选项,但这仅在安装时注册文件类型,而我希望能够在运行时注册文件类型。
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.
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 would be an option, but this only registers the filetype at installation-time while I want to be able to register filetypes at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Windows Vista(可能还有 Windows 7)中,文件关联已发生变化:如果文件已与程序关联并且您重新关联它,则双击该文件将不会使用新程序打开它。相反,关联会添加到“打开方式”下的列表中。另请参阅 在 Vista 中注册关联应用(网络存档,原始链接已消失)。
我不确定改变这个是否好。但是,这篇文章讨论了 注册表中您可以使用的各种键。但更好的是,这篇 codeproject 文章 让您准备好使用代码来关联运行时文件。我不知道它在 Vista+ 上的工作方式是否有所不同。
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).
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.
如果您需要在非管理场景中添加文件关联,您可以使用 这篇文章。查看“用户特定的文件关联”。
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".
就文件关联而言,从 XP 到 Vista/7 仅进行了一些更改,因此 XP 的大多数示例应该仍然有效。您唯一应该关心的是 Vista/7 中的“默认程序”设置,该设置在 XP 中不存在,并且会覆盖其他文件关联注册。
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. 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.