views:

548

answers:

2

Hi,

I already setting key and value in the registry entry by using RegSetValueExA, and it's created . But Now I want to delete that key and value from registry entry and for that I am using RegDeleteKey but its giving error 2 which is "The system cannot find the file specified.", can you tell me how can I solve this.

Thanks, Kamal Kumar Behera.

A: 

Does the registry key have sub-keys? RegDeleteKey won't do a recursive delete. If you're writing for Vista+, you can use RegDeleteTree, otherwise you will have to code a recursive delete, but there's example code on MSDN.

You can also use SHDeleteKey out of shlwapi.dll.

Tim Sylvester
A: 

Can you show any codes at all? It doesn't help anyone here narrow down your problem.

If I would take a guess though, there's something wrong with the way you have specified LPCTSTR lpSubKey in either RegOpenKeyEx or RegDeleteKey.

Example:

If you created a key:

HKEY_LOCAL_MACHINE\Software\Test

In order to delete it, you would need something like this:

RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software", 0, KEY_ALL_ACCESS, &RegHandle)
RegDeleteKey(RegHandle, test)

OR

RegOpenKeyEx(HKEY_LOCAL_MACHINE, someNullValue, 0, KEY_ALL_ACCESS, &RegHandle)
RegDeleteKey(RegHandle, L"Software\\test")

Make sure you check out the functions again at MSDN.

RegDeleteKey RegOpenKeyEx

Charles Khunt