在 Windows 7 C# 上访问注册表 [英] Accessing Registry on windows 7 C#

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

问题描述

我正在尝试制作一个更新程序,它在更新时将内部版本号写入主程序在检查更新时读取的 Windows 7 注册表.我浏览了 microsoft 页面上的 UAC 虚拟化知识库,但一无所获.我的 app.manifest 有

I am attempting to make an updater program, that when updates it writes a build number into the windows 7 registry which the main program reads when checking for updates. I've gone through the UAC virtualization kb at microsoft's page, and have found nothing. My app.manifest has

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

然而,当我查看 HKEY_Local_Machine\Software 时,构建条目不存在,我什至在 HKEY_USERS\_Classes\VirtualStore\Machine\Software 中也没有看到它.

and yet, when i look in HKEY_Local_Machine\Software the build entry is not there, i dont even see it in HKEY_USERS\_Classes\VirtualStore\Machine\Software either.

我用来进入注册表的代码是

the code i'm using to enter into registry is

            Registry.LocalMachine.CreateSubKey("SOFTWARE\\build");
        RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\build", true);

        myKey.SetValue("build", "3", RegistryValueKind.String);

有什么想法/建议吗?

推荐答案

如果您的应用程序面向 x86 平台,则在 x64 系统上运行时,它将使用具有以下名称的相应注册表节点:

If your application is targetting x86 platforms, when running on an x64 system, it will use the corresponding registry node with the following names:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ 或 HKEY_CURRENT_USER\SOFTWARE\Wow6432Node.

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ or HKEY_CURRENT_USER\SOFTWARE\Wow6432Node.

因此,如果您将构建的平台目标设置为 x86,在 x86 系统上,它将位于 HKEY_LOCAL_MACHINE\SOFTWARE 下,而在 x64 系统上,它将位于 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node 下,它是在 WOW64 上运行的应用程序的保留节点(Windows 32 位(Windows 64 位)模式.

So, if you set platform target to x86 for your build, on x86 systems it will go under HKEY_LOCAL_MACHINE\SOFTWARE whereas on x64 systems it will go under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node which is a reserved node for applications running on WOW64(Windows 32-bit on Windows 64-bit) mode.

有关详细信息,请参阅注册表反射

这篇关于在 Windows 7 C# 上访问注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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