C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-19-2010, 12:26 PM   #1
Registered User
 
Join Date: Mar 2005
Posts: 24
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.
Striph is offline   Reply With Quote
Old 03-19-2010, 12:38 PM   #2
Registered User
 
Join Date: Mar 2005
Posts: 24
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.
Striph is offline   Reply With Quote
Old 03-19-2010, 02:28 PM   #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!
stumon is offline   Reply With Quote
Old 03-22-2010, 06:07 AM   #4
Registered User
 
Join Date: Mar 2005
Posts: 24
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.
Striph is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Porting from 32 bit machine to 64 bit machine! anoopks C Programming 10 02-25-2005 08:02 PM
32 bit v.s. 64 bit xddxogm3 Tech Board 4 01-14-2005 09:58 AM
How to set an 32 bit allocation to 31 bit for address, 1 bit for flag? franziss C Programming 7 12-10-2004 08:18 AM
If the RGB color is (64, 64, 255), change it to (64, 255, 64). Grayson_Peddie C# Programming 2 06-14-2003 04:26 PM
Windows 98 problem Hannwaas A Brief History of Cprogramming.com 16 12-30-2001 12:01 PM


All times are GMT -6. The time now is 12:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22