Thread: c# OpenSubKey problem on 64 bit windows vs 32 bit.

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    37

    c# OpenSubKey problem on 64 bit windows vs 32 bit.

    I currently have a C# form app that reads a registry setting to find the location of a path, and then once it finds that it does its thing. I designed everything on a 32-bit OS and it worked flawlessly. I just got a new system running Windows 7 64-bit and have run into a problem.

    The program its looking for normally installs into the following registry key:

    HKLM\Software\ImagePro

    So i have my code setup like this:
    Code:
                if ((key = key.OpenSubKey("SOFTWARE\\ImagePro\\Current")) != null)
                {
                    string exePath = (string)key.GetValue("BinPath");
                    if (File.Exists(exePath + "\\convert.exe"))
                    {
    And it runs on a 32-bit OS just fine. I've found that on a 64-bit OS it no longer stores that registry info in the root Software tree, so when I run my program i have it setup to notify me that the ImagePro software is not installed, which since it can't find it is true, but it is installed. I've found that the registry now does this for 32 bit programs:

    HKLML\SOFTWARE\Wow6432Node\ImagePro

    Apparently all 32 bit registrys are in this "64 bit hive" branch of the Software registry keys.

    So I've changed my code to do this below and it now works on my 64-bit os.
    Code:
                if ((key = key.OpenSubKey("SOFTWARE\\Wow6432Node\\ImagePro\\Current")) != null)
                {
                    string exePath = (string)key.GetValue("BinPath");
                    if (File.Exists(exePath + "\\convert.exe"))
                    {
    Right now I have it hardcoded to just do the 64 bit key. Is there a way to read if an OS is 64 bit vs 32 bit? Or should I just read in the 64 bit registry key first, and if it fails, read in the 32 bit registry key? I've read that a 32-bit app is supposed to automatically read the Wow6432node entries on a 64bit OS, but its not so I'm lost right now. Anyone have any ideas or thoughts?
    Last edited by Striph; 03-19-2010 at 12:29 PM.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    I found the problem, my project was setup to compile for "Any CPU" which meant the program was being compiled as a 64 bit program which meant there was no registry reflection occuring. Once i changed the configuration options for the build to be x86 and set my code back to look in "Software\ImagePro" it started working again.

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    It will use the different registries for different Bit OS's.... But there is a simple way to check if you are on a 32 bit or 64 bit machine. Just create a bool method that checks IntPtr.Size and if its on a 32 bit system, it will be 4 bits, if it is on a 64 bit system, it will be 8.

    Read this: How to check whether the system is 32 bit or 64 bit ?

    Or just google it.
    The keyboard is the standard device used to cause computer errors!

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    Thanks for the link, yeah the boolean thing came to mind after i started posting, the post was initially on how to read just the wow3264node key but i branched out a bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  2. 32 bit v.s. 64 bit
    By xddxogm3 in forum Tech Board
    Replies: 4
    Last Post: 01-14-2005, 09:58 AM
  3. Replies: 7
    Last Post: 12-10-2004, 08:18 AM
  4. If the RGB color is (64, 64, 255), change it to (64, 255, 64).
    By Grayson_Peddie in forum C# Programming
    Replies: 2
    Last Post: 06-14-2003, 04:26 PM
  5. Windows 98 problem
    By Hannwaas in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 12-30-2001, 12:01 PM