RegOpenKeyEx fails on HKEY_LOCAL_MACHINE

后端 未结 1 1782
失恋的感觉
失恋的感觉 2021-01-12 18:42

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.         


        
相关标签:
1条回答
  • 2021-01-12 19:01

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

    long n = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE"),
                          0,KEY_QUERY_VALUE, &hk );
    

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

    #include <windows.h>
    #include <iostream>
    using namespace std; 
    
    int main() {
        HKEY hk;
    
        // Notice that it's SOFTWARE instead of \\SOFTWARE:
        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;
        }
    }
    
    0 讨论(0)
提交回复
热议问题