i want to check that registry of a particular program


actually i created two exe files and in the the second exe i want to check if registery of first exe.

if the exe of first exe is working fine then it will do some operations

if not then it will do diffrent operation

the first registry is

RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue);

RegSetValueEx(newValue,"microsoft security",0,REG_SZ,(LPBYTE)path,sizeof(path));

i check this manually in regedit .this is sucessfully added .

but

i add following code in second exe to check if the first registry is working or not

if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("microsoft security"), 0, KEY_ALL_ACCESS, &hKey)!=ERROR_SUCCESS)
{
cout<<"NOT WORKING\n";
}
else
{
cout<<"REGISTRY ALREADY PRESENT\n";
}

but this is always showing message "not working" but in actual key is present as i check manually wat could be reason

plzz provide improved code

You can't do it like that because you have to give it the full path to the key you want to open

RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\microsoft security",&hKey);

if (RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\microsoft security",&hKey)!=ERROR_SUCCESS)
{
cout<<"NOT WORKING\n";
}
else
{
cout<<"REGISTRY ALREADY PRESENT\n";
}


still same problem

getting same result

Edited 6 Years Ago by jamesbondbest: n/a

Please use code tags.

What does

cout << RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\microsoft security",&hKey) << endl;

say ?

My mistake -- "microsoft security" is a value, not a key. So you first have to open the key as you did in the first program

RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey)

Then attempt to read the value of "microsoft security" by calling RegGetValue()

i dont have much experience in registry . will u provide me working code

The best way to learn it is to do it yourself. I already gave you the link to the function you need to call. Experimenting with functions that you do not know how to use can be very enlightening. Instead of me just handing over the code to you, you give it a try and post back if you still have problems. Also post the code you tried.

This article has been dead for over six months. Start a new discussion instead.