HKEY_CLASSES_ROOT创建密钥权限 [英] HKEY_CLASSES_ROOT create key permissions

查看:183
本文介绍了HKEY_CLASSES_ROOT创建密钥权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我一直坚持将程序与新文件类型(新文件扩展名)相关联的任务.
我忙着上网,找到了您需要在注册表中编写的密钥以设置新的文件关联,但是看来我的程序无法写入注册表.
我正在运行Windows Vista启用了UAC(我需要测试默认配置,因为Vista默认启用了UAC),并且我很清楚地了解到HK_CLASSES_ROOT密钥修改受到限制.我的问题是:"UnauthorizedAccessException"失败了?我的问题是:我的程序是否可以通过某种方式获得足够的授权来写入HK_CLASSES_ROOT密钥?

如果没有,Windows是否提供一些接口来以编程方式创建文件关联?

我认为有一个解决方案可以使许多编写和创建文件关联的程序成为人们的了解tion.

谢谢您的帮助.
Hello all,

I'm stuck with my program on the task of associating a new file type (a new file extension) to my program.
I've serched the Internet and found out the key you need to write in the registry to setup a new file association but it seems that my program can't write to the registry.
I'm running Windows Vista with UAC enabled (I need to test the default configuration as Vista comes with UAC enabled by default) and I quite clearly understand that there are restrictions to HK_CLASSES_ROOT key modification.
In fact every attemp I've done to create these key programmatically has failed with an "UnauthorizedAccessException"

My question is: is there a way my program can gain enough authorization to write to the HK_CLASSES_ROOT key?

If not, does Windows offer some interface to programmatically create file associations?

I think there's a solution cause a know of many programs that write and create file association.

Thank you for your help.

推荐答案

您好-我想我的信息可以为您提供帮助:

首先,您可以制作一个Setup.exe文件,该文件将添加这些
注册表值.并且Setup.exe将自动在Windows Vista中以管理员身份运行.

但是,如果要修改regpath的权限,则
您需要使用 " 类,并调用枚举器(原始的"enum")
,即 "RegistryPermissionAccess" ,并按以下方式使用:

---------------------------------------------- --------------------------------
尝试
{

RegistryPermission权限=新 RegistryPermission( RegistryPermissionAccess.AllAccess," HKEY_CLASSES_ROOT \);
//这里我们执行"Demand()"
//将权限更改为"AllAccess".
Permission.Demand();

}
catch(Exception ex){
    MessageBox.Show(ex.Message.ToString());
}
------------------------------------- -------------------------------------------
安全说明:上面的代码可能需要管理员权限.
 

进一步阅读:
RegistryPermission类:
RegistryPermissionAccess枚举:
http://msdn.microsoft.com/zh-CN/library/system.security.permissions.registrypermissionaccess.aspx



我希望这些信息对您有帮助...

最好的问候,
Fisnik
Hi - I think my information can help:

Well, first off, you can make a Setup.exe file, which will add those
registry values. And the Setup.exe will automatically, run as administrator
in Windows Vista.

However, if you want to modify the permission of a regpath, then
you need to use the "RegistryPermission " class, and call the enumerator (orginal "enum"),
which is the "RegistryPermissionAccess" and use like this:

------------------------------------------------------------------------------
Try
{

RegistryPermission permission = new RegistryPermission( RegistryPermissionAccess.AllAccess, "HKEY_CLASSES_ROOT\");
//Here we perform the "Demand()" function, which
//will change the Permission to "AllAccess".
permission.Demand();

}
catch(Exception ex){
     MessageBox.Show(ex.Message.ToString());
}
--------------------------------------------------------------------------------
Security Note: The above code might require administrator privileges.
 

For further reading:
RegistryPermission Class:
http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission.aspx

RegistryPermissionAccess Enumeration:
http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermissionaccess.aspx



I hope this information was helpful...

Best regards,
Fisnik


这篇关于HKEY_CLASSES_ROOT创建密钥权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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