Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
This call is used to open the Registry Key:
C++
HKEY hKey;
LPCTSTR CFDW_Reg_Key = TEXT("SOFTWARE\\Company A\\Application_Name\\1.13"); 

result = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
    CFDW_Reg_Key,
    NULL,           
    KEY_READ | KEY_WRITE,
    &hKey);

The following call works on a Windows XP computer, but returns an error code=2 on my Windows 7 computer.
C++
HKEY hKey;
DWORD buflen;
LPCWSTR REG_INSTALL_PATH_NAME = TEXT("InstallPath");
		
result = RegQueryValueEx(hKey, REG_INSTALL_PATH_NAME, 0, 0, 0, &buflen);

Any help would be greatly appreciated.

Thank you.

Scott
Posted
Updated 9-May-12 18:29pm
v2
Comments
[no name] 10-May-12 8:31am    
Hi,

As the others have hinted at... on a 64 bit OS running a 32 bit application... you will need to add the flag KEY_WOW64_64KEY depending on the return value of IsWow64Process()

Best Wishes,
-David Delaune

Return code 2 means ERROR_FILE_NOT_FOUND...
Does your application run as a 64bit application or as a 32bit application on Windows 7 (you can check that with the task manager)? The problem might arise from the different registry hives for 32bit and 64bit applications. A 32bit program actually looks at HKLM\Software\Wow6432Node when you tell it to open HKLM\Software. Hence I'd suggest to scrutinize these possibilities.
 
Share this answer
 
Comments
Chuck O'Toole 10-May-12 2:53am    
True, it makes a difference. Since the OP's registry key looks like it's related to the installation procedure, another thing to look for is a mismatch between the "bitness" of the install package versus the "bitness" of the running application. I had an issue where the application was 32-bit but the installation was 64-bit so the installation put the key in one registry hive and the code was looking for it in another.
try this.

C++
REGSAM flag = KEY_WOW64_32KEY or KEY_WOW64_64KEY; // fake code

result = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
    CFDW_Reg_Key,
    NULL,
    KEY_READ | KEY_WRITE | flag,
    &hKey);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900