Ben H
Ben H

Reputation: 77

Accessing Registry on windows 7 C#

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?

Upvotes: 0

Views: 4699

Answers (1)

Yiğit Yener
Yiğit Yener

Reputation: 5986

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

Upvotes: 1

Related Questions