如何将应用程序设置为以编程方式打开某种类型的文件的默认程序 [英] How to set an application as the default program of opening a certain type of file programmatically

查看:145
本文介绍了如何将应用程序设置为以编程方式打开某种类型的文件的默认程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式将我的程序设置为某些文件类型(.pdf)的默认查看器?我是否需要将一些信息写入注册表或使用某些Windows API(因为用户可以手动执行)?

我已经(对于pdf)已经使用Inno设置脚本设置了相应的注册表项:

根:HKCR;子项:.pdf"; ValueType:字符串; ValueName:"; ValueData:"myprogramdoc";

根:HKCR;子项:"myprogramdoc"; ValueType:字符串; ValueName:"; ValueData:"myprogram PDF文档";

根:HKCR;子项:"myprogramdocument \ DefaultIcon"; ValueType:字符串; ValueName:"; ValueData:"{app} \ myprogram.exe,1";

并且这些注册表对于win 7来说效果很好.但是在XP下,如果已经将其他查看器设置为默认查看器(foxit),则不会以pdf格式显示我的图标(我必须手动进行-选择我的程序作为默认查看器) .

How to set my program to be default viewer for some file type (.pdf) programmatically? Do I need to write some info into registry or to use some windows api (as user can do manually)?

I already (for pdf) set the corresponding registry keys using Inno setup script:

Root: HKCR; Subkey: ".pdf"; ValueType: string; ValueName: ""; ValueData: "myprogramdoc";

Root: HKCR; Subkey: "myprogramdoc"; ValueType: string; ValueName: ""; ValueData: "myprogram PDF Document";

Root: HKCR; Subkey: "myprogramdocument\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\myprogram.exe,1";

and these registries work well for win 7. But under XP, if there is already set some other viewer as default (foxit), my icon will not be presented for pdf (I have to do manually - to choose my program as default viewer).

推荐答案

是的,它写在注册表中.如果您使用的是google,则在很多地方都对它进行了详细说明.
Yes, it''s written in the registry. If you google, it''s fully explained in many places.


这篇关于如何将应用程序设置为以编程方式打开某种类型的文件的默认程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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