Reputation:
I've been playing with this and I can't understand why the RegDeleteKey function is resulting to a file not found error..
I created this test key and it exists. HKLM\Software\test I am also the administrator of this computer. OS is Vista 32 bit.
int main()
{
HKEY hReg;
LONG oresult;
LONG dresult;
oresult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\test", 0, KEY_ALL_ACCESS, &hReg);
if(oresult == ERROR_SUCCESS)
{
cout << "Key opened successfully." << endl;
}
dresult = RegDeleteKey(hReg, L"SOFTWARE\\test");
if(dresult == ERROR_SUCCESS)
{
cout << "Key deleted succssfully." << endl;
}
else
{
if(dresult == ERROR_FILE_NOT_FOUND)
{
cout << "Delete failed. Key not found." << endl;
cout << "\n";
}
}
RegCloseKey(hReg);
return 0;
}
The output is:
key opened successfully delete failed. key not found.
Upvotes: 1
Views: 5859
Reputation: 1492
Two things to check for error 2 / "file not found":
If you create a folder like HKCU > Software > CompanyName and then store a value like option = "foo" with RegSetValueEx, then you need to delete this with RegDeleteValue or RegDeleteValueEx.
Upvotes: 2
Reputation: 10660
According to the MSDN page, the second parameter is a subkey of the key in hKey:
The name of the key to be deleted. It must be a subkey of the key that hKey identifies, but it cannot have subkeys. This parameter cannot be NULL.
That means your code actually tries to delete HLKM\SOFTWARE\test\SOFTWARE\test.
You probably want to try something like:
RegDeleteKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\test");
This may come in handy.
Upvotes: 4