C#WOW6432注册表节点混乱 [英] C# WOW6432 registry node messin things up

查看:35
本文介绍了C#WOW6432注册表节点混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试完成写入注册表以使C#应用程序在启动时运行的简单任务.

Trying to do the simple task of writing to the registry to make a C# application run at startup.

使用基本的 Win32.RegistryKey 设置,但由于某种原因,它一直将我的密钥添加到/SOFTWARE/WOW6432/Microsoft/Windows.等目录中,而不是普通目录ol /SOFTWARE/Microsoft/Windows ..

Using the basic Win32.RegistryKey setup but for some reason it keeps adding my keys into the /SOFTWARE/WOW6432/Microsoft/Windows.. etc directory instead of plain ol /SOFTWARE/Microsoft/Windows..

尝试阅读一下,但似乎没有一个简单的答案:我如何专门将密钥写入/SOFTWARE/Microsoft/Windows 注册表项,而不是将其写入 WOW6432 ?我已检查以确保我的Visual C#Express解决方案文件的平台列为x86 ...因此它可以正确编译...我只是不希望该 wow6432 目录.

Tried reading up on it a bit but there didn't seem to be a simple answer to this question: How to I specifically write a key to the /SOFTWARE/Microsoft/Windows Registry Key instead of it writing to WOW6432? I've checked to make sure my Visual C# Express solution file had the platform listed as x86... so it's compiling correctly... I just don't want that wow6432 directory.

感谢您的任何建议!

我现在正在使用以下方法,但仍然没有成功:

I'm now using the following and still no success:

Microsoft.Win32.RegistryKey localKey32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);

推荐答案

您的进程针对x86(即,它是一个32位进程),并且在WOW64仿真器下的64位计算机上运行时,受WOW64影响的注册表项

Your process targets x86 (i.e. it is a 32-bit process) and when run on a 64-bit machine under the WOW64 emulator, registry redirection comes into play. For certain parts of the registry the system maintains two distinct views, one for 32 bit processes and one for 64 bit processes. The list of keys affected by redirection is here: Registry Keys Affected by WOW64.

重定向对应用程序是透明的.32位进程访问 HKLM \ Software ,并且不知道(实际上不需要知道),64位操作系统实际上正在访问 HKLM \ Software \ Wow6432Node .

Redirection is transparent to an application. A 32 bit process access HKLM\Software and does not know (indeed does not need to know), that the 64 bit OS is actually accessing HKLM\Software\Wow6432Node.

您有许多可用的选项:

  1. 切换到AnyCPU目标,以便您的进程将根据基础操作系统以32位或64位运行.在Express版本中很难做到这一点,因为无法从IDE中指定目标平台.
  2. 显式打开注册表的64位视图.在.net中,这需要 RegistryView 枚举.但是,请注意,此功能需要.net 4,并且对于.net的早期版本,需要p/invoke才能打开注册表视图.
  3. 继续定位到目标x86并写入 HKLM \ Software .处理启动注册表项上的运行时,64位系统将读取注册表的两个视图.换句话说,您现有的方法已经有效!
  1. Switch to the AnyCPU target so that your process will run as either 32 bit or 64 bit depending on the underlying OS. This is awkward to achieve in the Express version because the target platform cannot be specified from the IDE.
  2. Explicitly open a 64 bit view of the registry. In .net this requires the RegistryView enumeration. However, note that this functionality requires .net 4 and for earlier versions of .net, p/invoke is required to open views of the registry.
  3. Continue to target x86 and write to HKLM\Software. A 64-bit system will read both views of the registry when processing the run at startup registry keys. In other words your existing approach already works!

最后一点,我要评论的是,设置此注册表项的任务最好留给安装程序.在 HKLM \ Software 下修改密钥需要管理员权限,通常,您只能期望在安装时具有管理员权限.

As a final point I would comment that the task of setting up this registry key is best left to an installation program. Modify keys under HKLM\Software requires admin rights and typically you can only expect to have admin rights at install time.

这篇关于C#WOW6432注册表节点混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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