views:

1912

answers:

1

Hi I'm trying to read a registry value that gives me the path to firefox.exe. This is stored under

HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 3.0.10\bin

(the version number can be found somewhere else)

But I cant seem to get RegOpenKeyEx to return ERROR_SUCCESS for anything under

HKEY_LOCAL_MACHINE

so this test fails:

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("\\SOFTWARE"),0,KEY_QUERY_VALUE,&keyHandle) == ERROR_SUCCESS)

while this test passes:

if(RegOpenKeyEx(HKEY_CLASSES_ROOT,TEXT("\\Shell"),0,KEY_QUERY_VALUE,&keyHandle) == ERROR_SUCCESS)
+12  A: 

The following code failed on my machine with the error code 161, which means "bad path" (look it up in winerror.h):

#include <windows.h>
#include <iostream>
using namespace std; 

int main() {
    HKEY hk;

    long n = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("\\SOFTWARE"),
                      0,KEY_QUERY_VALUE, &hk );
    if ( n == ERROR_SUCCESS ) {
     cout << "OK" << endl;
    }
    else {
     cout << "Failed with value " << n << endl;
    }
}

I then changed the call to RegOpenKeyEx to use "SOFTWARE" (note no leading slashes) and it worked.

anon
Thx, that was it! I think that it might be caused by that SOFTWARE is saved in a separate file (got this info from wikipedia though), and isnt a folder like Shell is in HKEY_CLASSES_ROOT
Emile Vrijdags