Wednesday, February 23, 2011

Windows: Of 32-bit and 64-bit application registry

I recently ran into a problem where i was doing some development work and tried to read the value of a registry from under HKLM:software\microsoft\"Myprogram" using a C# program. The program kept failing and was not able to read it; it was not even able to open the said registry key. Initially, i thought that it might be a permissions problem, but NO !! To add to my frustation, i can clearly "see" the key being present in the registry.

After banging my head in the wall for some time and googling, i finally found that on 64 bit machines (where i a was doing my development work) there are 2 versions of the application registry. One for 32 bit applications to use and another version for 64 bit appications to use. regedit for 32-bit version resides under C:\Windows\System32 and 64-bit version resides under C:\Windows\SysWOW64.

The installer which wrote those registry keys was a 32 bit application; hence the registry entries were made to 32 bit version of the registry. The C# application that I was developing was targeting "x86" architecture. When I ran the application it always tried to open the 64 bit version of the registry and kept failing. I then changed the "platform target" in the project properties page from "x86" to "AnyCPU" and wholla!! problem solved :)

-----
Q. Why is 6 afraid of 7 ?
A. Because 7 8 9 :)
-----

No comments:

Post a Comment