gpt4 book ai didi

c# - 有没有办法以编程方式设置 "UserChoice"注册表项以接管文件类型关联?

转载 作者:可可西里 更新时间:2023-11-01 09:15:53 25 4
gpt4 key购买 nike

我一直在尝试找到一种方法来更改默认文件关联Windows 7 中的特定文件扩展名。我有一个用于查看 .tif 的应用程序如果它不是该文件的默认查看器,我想提示用户的文件类型。如果他们选择将其设为默认值,我想覆盖当前的默认查看器。如果没有安装其他查看器,这将正常工作系统。当用户选择了另一个查看器时,我无法在此处更改控制它的注册表项:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tif\UserChoice

I have scoured the web trying to find someone that has done this, but nobodyseems to have any answers. When I try to update the "Progid" value within thiskey, I get a "Cannot write to the registry key" or "Requested registry access isnot allowed" errors. The code is simple enough:

var path = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.tif\UserChoice";
var key = Registry.CurrentUser.OpenSubKey(path, true);
key.SetValue("Progid", "myprogid...");

这个 key 是否有一些特殊的保护来防止它被以编程方式编辑?

最佳答案

为了能够写入 key UserChoice,您需要在写入之前获取该 key 的所有权(如 this 代码 - 不是在 c# (C++) 中,但我认为它可以以相同的方式完成)。

您将能够写入 key ,并且您的文件关联代码将起作用!

编辑:另见 Registry Key Security and Access Rights on MSDN

关于c# - 有没有办法以编程方式设置 "UserChoice"注册表项以接管文件类型关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com