Search code examples
c++registrykey

To read windows registry using a C++ program on Windows 7


I want perform a couple of basic operations on windows registry. I wrote a small C++ program to read current user key. Below is the code snippet. I am honestly not sure why RegOpenKeyEx() isn't returning ERROR_SUCCESS. Please advice.

#include <Windows.h>

#include <iostream>
using namespace std;

int main(){

    HKEY hkey;

    if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SoftwareDevShed TutorialTest"), 0, KEY_ALL_ACCESS, &hkey) != ERROR_SUCCESS)
        cout<<"Error opening the key"<<endl;
    else 
        cout<<"Success"<<endl;
    system("PAUSE");
    return 0;

}

Solution

  • Where have the backslashes gone here: TEXT("SoftwareDevShed TutorialTest")? Shouldn't that read TEXT("Software\\DevShed Tutorial\\Test")?