gpt4 book ai didi

c# - 如何使用 RegistryKey.SetValue

转载 作者:太空狗 更新时间:2023-10-29 23:00:35 24 4
gpt4 key购买 nike

我正在尝试使用以下代码创建一个新的注册表项并收到此错误:

Cannot write to the registry key.

我哪里错了???

var rs = new RegistrySecurity();
string user = Environment.UserDomainName + "\\" + Environment.UserName;
rs.AddAccessRule(new RegistryAccessRule(user,
RegistryRights.WriteKey | RegistryRights.SetValue,
InheritanceFlags.None,
PropagationFlags.None,
AccessControlType.Allow));
RegistryKey key;
key = Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", RegistryKeyPermissionCheck.ReadSubTree, rs);
key.SetValue("kashif", 1, RegistryValueKind.DWord);
key.Close();

最佳答案

您需要打开新创建的 key 以进行读/写访问:

key = Registry.LocalMachine.CreateSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Policies\System",
RegistryKeyPermissionCheck.ReadWriteSubTree, // read-write access
rs);

关于c# - 如何使用 RegistryKey.SetValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14531142/

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