How to remove a registry value and key from a registry entry
I already set the key and value in the registry entry with RegSetValueExA
and it was generated. But now I want to remove this key and value from the registry entry, and for that I use RegDeleteKey
, but it gives error 2 which is "The system cannot find the file specified." Can you tell me how I can solve this.
Can you show any codes at all? It doesn't help anyone narrow down your problem.
If I were to assume there is something wrong with the way you specified the LPCTSTR lpSubKey in RegOpenKeyEx or RegDeleteKey.
Example:
If you created a key:
HKEY_LOCAL_MACHINE\Software\Test
To remove it, you 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 the features again on MSDN.
source to share
Are there any subkeys in the registry key? RegDeleteKey
will not perform recursive delete. If you are writing for Vista + you can use RegDeleteTree
, otherwise you have to code recursive delete, but there is sample code on MSDN .
You can also use SHDeleteKey
from shlwapi.dll file.
source to share
Two things to check for error 2 / "file not found":
- Make sure it is not a "value" within a key, and not an actual key.
If you create a folder like HKCU> Software> CompanyName and then store a value like = "foo" with RegSetValueEx, you need to delete that with RegDeleteValue or RegDeleteValueEx.
- If it is a 64-bit OS, there are separate registry views for 32-bit and 64-bit. By default, a 32-bit application will use 32-bit representation for everything, but if you created an entry with KEY_WOW64_64KEY for some reason, then you need to use it when deleting.
source to share