本文介绍了使用RegistryKey.OpenSubKey()的SecurityException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此行有效:

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(
    baseKeyName + subKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

尽管这些行会产生 SecurityException-OpenSubKey 行上不允许请求的注册表访问:

While these lines produce a SecurityException - Requested registry access is not allowed on the OpenSubKey line:

RegistryKey baseKey = RegistryKey.OpenBaseKey(
   RegistryHive.LocalMachine, RegistryView.Registry32);
RegistryKey registryKey = baseKey.OpenSubKey(
   baseKeyName + subKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

在同一台Win7计算机上.

On the same Win7 machine.

我这样做是因为在真实"代码中有一个条件,它将在64位计算机上使用Registry64 RegistryView.

I'm doing it this way because in the 'real' code there is a conditional that will use the the Registry64 RegistryView on 64 bit machines.

有人有任何想法或解决方法吗?

Anyone got any ideas or workarounds?

推荐答案

除非应用程序以管理员身份运行,否则不允许写入LocalMachine注册表区域.

Writing to the LocalMachine registry area is not allowed unless the application is running elevated as an administrator.

这篇关于使用RegistryKey.OpenSubKey()的SecurityException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:13