Accessing Registry on windows 7 C#

徘徊边缘 提交于 2019-12-11 20:39:40

问题


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" />

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);

any ideas/suggestions?


回答1:


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\ or HKEY_CURRENT_USER\SOFTWARE\Wow6432Node.

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.

For more information see Registry Reflection



来源:https://stackoverflow.com/questions/6799584/accessing-registry-on-windows-7-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!