文件扩展名文件关联和 ClickOnce
我想创建自己的扩展而不更改我的注册表文件。我有一个 VB.NET 项目,我首先想创建自己的扩展名,例如“.abc”。之后,如果有任何像 xxxxxx.abc 这样的文件,当有人尝试打开此文件时,我希望 Windows 启动我的项目并打开该文件。
I want to create my own extension without changing my registry file. I have a VB.NET project, and I first want to create my own extension like ".abc". Afterwards, if there is any file like xxxxxx.abc when a person tries to open this file, I want Windows to start up my project and open that file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面说不可能的评论有点误导。
如果不更改注册表,这是不可能实现的,但是对于 clickonce 应用程序来说,无需自己编写任何代码,就完全可以做到这一点。
当您在 clickonce 应用程序中创建文件关联时,所需信息将写入 HKEY_CURRENT_USER 配置单元,并覆盖在 HKEY_LOCAL_MACHINE 级别设置的任何内容。卸载应用程序时,文件关联条目也会从 HKCU 中删除,这意味着 HKLM 中已设置的任何关联(如果有)将从那时起使用。 IOW,您只能在每个用户的基础上覆盖(或设置)文件关联。
有关如何设置文件关联的详细信息,请检查以下链接:
请注意,还有一个VS2010 中内置的对话框可帮助进行此设置:
The comment above saying that it is impossible is a little misleading.
This is impossible to do without changing the registry, but for a clickonce application it is totally possible to do without having to write any code yourself.
When you create a file association in a clickonce application the required information is written to the HKEY_CURRENT_USER hive, and overrides whatever is set at the HKEY_LOCAL_MACHINE level. When your application is uninstalled the file association entries are also removed from HKCU, which means any association already set in HKLM (if any) will be used from then on. IOW you can only override (or set) the file association on a per-user basis.
For more information on how to set the file association, check these links:
Note that there is also a dialog built into VS2010 to help set this up: