积极答复者
如何将对应文件类型修改成默认的关联程序

问题
-
RegistryKey key;
//1 设置自定义文件的双击打开
key = Registry.ClassesRoot.CreateSubKey(extendName);
key.SetValue("", directions);
key = key.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
key.SetValue("", string.Format("{0} %1", appPath, RegistryValueKind.String));
key = Registry.ClassesRoot.CreateSubKey(extendName);
key.SetValue(extendName, extendDefaultSet);
//2 设置自定义文件的默认图标
//key = Registry.ClassesRoot.OpenSubKey(extendDefaultSet, true);
key = key.CreateSubKey("DefaultIcon");
string path = AppPath.StartupPath;
string fileName = path + @"\res_img\client.ico";
key.SetValue("", string.Format("{0},0", fileName, RegistryValueKind.String));
RegistryKey hk_root = Registry.ClassesRoot;
key = hk_root.OpenSubKey(extendName, true);
我是这样写的,但是右键打开方式里没有我的WPF应用程序。
- 已编辑 Marry_qing 2016年1月20日 6:32
答案
-
您好 Marry_Xia,
UserChoice是当用户右键点击一个文件后,选择默认应用程序后,这个注册表项就会被产生或修改。 这个注册表项也是可以修改的,如果您不能修改它,说明您还没有修改它的权限。关于注册的访问权限,您可以参考以下文档。
https://msdn.microsoft.com/en-us/library/ms724878(VS.85).aspx
为了获取注册表的使用权限,我们需要使用到AddAccessAllowedAceEx和RegSetKeySecurity方法。
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374951(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/aa379314(v=VS.85).aspx
Best Regards,
Xavier Eoro
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Marry_qing 2016年1月20日 6:32
全部回复
-
您好 Marry_Xia,
>> "如何将对应文件类型修改成默认的关联程序"
根据您的描述,我不是很清楚你的问题到底是什么,可以详细的描述一下您的问题吗?我查看了您的代码,你在代码中设置了文件关联。设置成功后,当双击包含此扩展名的文件。 Windows会使用您设置的应用程序打开此文件。
>>"我是这样写的,但是右键打开方式里没有我的WPF应用程序"
在右键->打开方式里,Windows会把有可能打开这个文件的应用程序列出来。这时候您需要手动选择您的应用程序,当下次再使用右键->打开方法的时候,您的应用程序就会出现在推荐的应用程序列表中。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
您好 Marry_Xia,
>>"不用手动选择自己的应用程序就可以把文件列出来"
您想要的是不是在打开方式->推荐的应用程序中出现您的应用程序?我们可以通过修改以下注册表项来完成。在OpenWithList目录下添加您的应用程序。
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ext\OpenWithList
以下为跟OpenWithList相关的官方文档。
https://msdn.microsoft.com/zh-cn/library/bb166549.aspx>>"当我用自己软件打开后再用比如2345看图王等看图软件打开时,右键打开方式里就没有了。"
有可能其他软件把OpenWithList目录下的键值都清空了。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
您好 Marry_Xia,
关联的话需要创建注册表项并放入HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ext\OpenWithList下面。如果要取消的话需要把当前应用程序对应的注册表项删除即可。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
您好 Marry_Xia,
修改这个注册表项需要管理员权限,您需要以管理员身份运行您的这个应用程序。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
您好 Marry_Xia,
UserChoice是当用户右键点击一个文件后,选择默认应用程序后,这个注册表项就会被产生或修改。 这个注册表项也是可以修改的,如果您不能修改它,说明您还没有修改它的权限。关于注册的访问权限,您可以参考以下文档。
https://msdn.microsoft.com/en-us/library/ms724878(VS.85).aspx
为了获取注册表的使用权限,我们需要使用到AddAccessAllowedAceEx和RegSetKeySecurity方法。
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374951(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/aa379314(v=VS.85).aspx
Best Regards,
Xavier Eoro
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Marry_qing 2016年1月20日 6:32