Can someone please explain to me the first two parameters of RegDeleteKeyEx(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved) function, i.e. what's meant by SubKey in this case and is the hkey obtained from RegOpenKeyEx() function?
Yes, the first one is usually a key handle obtained via RegOpenKeyEx() or RegCreateKey() as explaind @ MSDN Online. The second parameter is a C string that represents the subkey to delete. Note that it has to be a child of the key specified by the key handle in parameter 1. But really, what else can I tell you that MSDN hasn't?
Hmm ok, I guess this code should run fine then... However it doesn't delete the "easy" registry. Why could this be? (btw I'm using 64 bit operating system)
Is your program running under an admin account? That's likely necessary. Also, when doing registry code I inevitably find I have to actually log return values from everything until I get it working. I'm always really careful about that with registry code. One time I blew a whole registry out with an error in my code. You would be amazed how little you can do with a Windows computer with the registry completely gone!
You're using the wrong access flags. Replace KEY_CREATE_SUB_KEY with KEY_ALL_ACCESS. You may also be getting locked out of the local machine registry section due to Windows 7 or Vista UAC restrictions. Change the manifest settings to requireAdministrator or right-click your EXE and "Run as Administrator"
Yes, I am running under an admin accout... Thanks for the tip, but I still can't figure out what's wrong. I thought that I misinterpreted the lpSubKey in RegDeleteKeyEx() which in my case is the name of the registry, but now it seems right so I'm confused even more...
0 == ERROR_SUCCESS. Is "easy" a registry key, or a registry key value? Keys appear to the left in the treeview in the registry editor, while values only appear in the right hand side.
Also track the error codes returned by all registry function calls, like RegOpenKeyEx(). Also note that I don't know every return code's meaning. Use FormatMessage() to obtain error messages.
BTW, you are missing the TEXT() macro (or the _T() macro) around your string literals.
Sorry 0 was the return value to the GetLastError() function. But when I used FormatMessage() the message that I got is "The system cannot find the file specified.". And yes "easy" is the value name.
Ok, thanks. That's what I've been looking for but now I get a message of access is denied even though I'm running the program under an administrator account.