为什么注册表写在不同的位置比预期? [英] Why is registry written in different location than expected?

查看:248
本文介绍了为什么注册表写在不同的位置比预期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写一个注册表子项及其相应的值注册表是这样的:

I tried to write a registry subkey and its corresponding value to registry like this:

const string subKey = @"SOFTWARE\Apple\Banana\";
const string regKey = "pip";

var rk = Registry.LocalMachine.OpenSubKey(subKey);
if (rk == null)
    rk = Registry.LocalMachine.CreateSubKey(subKey);

var rv = rk.GetValue(regKey);
if (rv == null)
    rk.SetValue(regKey, "XXX");

return rv.ToString();

现在的问题是,我当我手动期待中的位置(通过注册表编辑器)我看不到文件夹 SOFTWARE\Apple\Banana HKLM

Now the problem is that I when I look in the location manually (via regedit) I cannot see the folder SOFTWARE\Apple\Banana in HKLM.

但是当我再次运行上面的代码和调试,我可以看到,无论 Registry.LocalMachine.OpenSubKey(子项) rk.GetValue(REGKEY)得到保存的前值。然而,我不要通过注册表编辑器中看到给定位置的值。因此,对搜索注册表,我可以看到上面的键和值在以下位置:

But when I run the above code again and debug, I can see that both Registry.LocalMachine.OpenSubKey(subKey) and rk.GetValue(regKey) yields the before saved values. Yet I do not see the values in the given location via regedit. So on searching the registry, I can see the above keys and values in following locations:


  1. HKEY_CURRENT_USER \Software\Classes\VirtualStore\MACHINE\SOFTWARE\Apple\Banana

HKEY_USERS\S-1-5-21-44266131-1313801407-2392705078-1000\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Apple\Banana

在这两个值保持完全按照我得救了。所以,我意识到这是从那里我的应用程序在我的代码,虽然读取值我称之为从 HKLM\SOFTWARE\Apple\Banana\ ..

Under both which the values remain exactly as I saved. So I realise this is from where my app reads the value though in my code I call it from HKLM\SOFTWARE\Apple\Banana\..


  1. 这是怎么回事?这是否与访问权限问题?

  1. Why is this happening? Is it related to access rights issue?

这是预期的行为?在这个意义上,这个值是对我很重要,所以我只知道如果没有与自动搬迁相关的一些风险!

Is this expected behaviour? In the sense, this value is very important to me, so I am just knowing if there is some risk associated with auto-relocation!

有一个适当的写作的方式,注册表,使之保持在它的确切位置。

Is there a proper way of writing to registry so that it remains in its exact location..

我的帐户是管理员之一,我我用32位Windows 7

My account is administrator one, and I am using 32 bit windows 7.

编辑:正如我才知道,该注册表项被保存在当前用户的位置,而不是HKLM。当我查询了reg值从不同的帐户,我没有得到的值。总之,首先它所有保存到HKLM无点:(

As I came to know, the registry entry is stored in current users location rather than HKLM. And when I query for the reg value from a different account, I do not get the value. In short, no point in first of all saving it to HKLM :(

推荐答案

是的,这是正确的行为,这是因为发生你有足够的权限来直接写入到HKLM配置单元中。这就是所谓的虚拟化和文件系统发生为好,它一直在,因为Vista的操作系统行为。

Yes this is correct behaviour and it is happening because you have insufficient privileges to write directly to the HKLM hive. It's called virtualisation and happens for the file system as well, it has been a behaviour in the OS since Vista.

您应该继续为你和也你写,Windows将透明地重定向你同样的HKLM键读取尝试。

You should continue as you are and attempt to also read from the same HKLM key you are writing to, Windows will transparently redirect for you.

普里特具有的kindly提供一个MSDN链接,你应该仔细阅读。

Preet has kindly provided a MSDN link which you should read thoroughly.

请注意,当您访问一键HKLM下,你还应该包括你想要的权限,即使你以管理员身份运行(因为关键是不能自动以管理员权限打开,你有权要求它):

Note that when you access a key under HKLM you should also include the permissions you want, even if you are running as administrator (because the key is not automatically opened with admin rights, you have to request it):

key = key.OpenSubKey(keyname, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl);

这篇关于为什么注册表写在不同的位置比预期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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