本文介绍了使用 C# 编辑了注册表,但无法使用 regedit 找到更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我使用以下代码通过 C# 更改了我的注册表:


I changed my registry via C# with the following code:

RegistryKey regKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
RegistryKey openSubKey = regKey.OpenSubKey(@"SOFTWARE\ASA\Suite", true);
openSubKey?.SetValue("Password", encryptedString, RegistryValueKind.String);
openSubKey?.SetValue("UserName", UserNameTextBox.Text, RegistryValueKind.String);
openSubKey?.SetValue("DomainName", DomainNameTextBox.Text, RegistryValueKind.String);
openSubKey?.Close();
regKey.Close();

这些条目已经存在,只是被替换了.当我使用相同类型的代码读取设置时,我会得到正确的设置,但是当我使用 regedit.exe 打开注册表并手动搜索它时,我只能找到旧值.在 regedit.exe 中是这个路径:Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ASA\Suite我已经研究了没有 WOW6432Node 的路径(甚至在 HKCU 中),但根本没有 ASA 条目.
有人知道那可能是什么吗?为什么我看不到我所做的更改?我在这里完全不解...

These entries did already exist and were only replaced. When I use the same kind of code to read the settings I get the correct settings back, BUT when I open the registry with regedit.exe and search for it manually I find only the old values. In the regedit.exe it is this path: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ASA\SuiteI already looked into the path without WOW6432Node (and even in the HKCU) but there is no ASA entry at all.
Has someone an idea what that could be? Why don't I see the changes I made? I am completly puzzled here...

我将我的项目从 anyCPU 更改为 x86 并且没有任何更改,但是一旦我将其更改为 x64,读取的密钥就是 regedit.exe 显示的密钥.但是我打开了注册表配置单元的 32 位变体,当我在这里写一些东西时,问题仍然存在……为什么我看不到所做的更改?x64 Windows 下的 x86 应用程序应该自动写入 WOW6432Node,不是吗?

I changed my project from anyCPU to x86 and no change, but as soon as I changed it to x64 the keys read were the ones that regedit.exe shows. But I open the 32bit variant of the registry hive, and when I write something here the question persists... why can't I see the changes made? A x86 app under x64 Windows should automatically write to the WOW6432Node, shouldn't it?

我在 x86 Windows 上测试了 x86 版本.我更改了注册表并且可以读取它,但是使用 regedit 我看不到更改...是这样吗?

I tested the x86 version on an x86 Windows. I change the registry and can read it, but with regedit I cannot see the changes... wtf is this?

我在 HKCR\VirtualStore\MACHINE\SOFTWARE\ASA\Suite 下找到了已更改的密钥我不知道为什么,但我搜索了一个答案并将其发布在这里.

I found the changed keys under HKCR\VirtualStore\MACHINE\SOFTWARE\ASA\Suite I don't know why yet, but I search for an answer and post it here.

推荐答案

好的,我知道答案了.我不想使用清单,所以我删除了它,因此没有被问到是否必须提升应用程序.因此,因为普通用户(即使登录用户具有管理员权限)无法写入 HKLM,它向 HKCU\VirtualStore 写入了一个密钥...这样我的应用程序也可以读取密钥,但在 regedit 中.exe 这不是预期的地方.为了解决这个问题,我实现了一个清单并使用 requestsExecutionLevel 更改了行:

Ok, I have the answer. I didn't wanted to use a manifest so I removed it and thus didn't got asked if the app had to be elevated. So, because a normal user (even if the logged in user had admin rights) can't write to the HKLM, it wrote a key to HKCU\VirtualStore... that way my app could also read the keys but in the regedit.exe it was not where it was expected.To get around this I implemented a manifest and changed the line with the requestedExecutionLevel:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

现在我什至不必构建 x64 和 x86 版本,但可以改用 Any CPU 并让我的应用程序完成工作(即:查看是否使用 RegistryView.Registry32RegistryView.Registry64)

Now I don't even have to build an x64 and an x86 version but can use Any CPU instead and let my app do the work (i.e.: to look if to use the RegistryView.Registry32 or RegistryView.Registry64)

这篇关于使用 C# 编辑了注册表,但无法使用 regedit 找到更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:51