Problem in deleting the windows registery key and it's sub key
-
Hi I have again some problem regarding windows registery. I am trying to delete a key and it's sub keys and all the corressponding values. Here is the code which I am using: HKEY m_htKey; LONG res; const char* lpSubNsKey = "SOFTWARE\\N K Product"; res = RegOpenKeyEx(HKEY_CURRENT_USER ,lpSubNsKey,0,KEY_ALL_ACCESS,&m_htKey); if (res == ERROR_SUCCESS) { //res = RegDeleteKey(m_htKey,lpSubNsKey); LONG status = SHDeleteKey( m_htKey,lpSubNsKey); RegCloseKey(m_htKey); } In the above code,the RegOpenKeyEx() is returning 0 means registery is getting opened but the SHDeleteKey() is returning 2 i.e. it's error code message is "The system cannot find the file specified". But the key name is available there in the registery. So,can you please suggest me what could be the problem?
With Regards Neeraj Sinha
-
Hi I have again some problem regarding windows registery. I am trying to delete a key and it's sub keys and all the corressponding values. Here is the code which I am using: HKEY m_htKey; LONG res; const char* lpSubNsKey = "SOFTWARE\\N K Product"; res = RegOpenKeyEx(HKEY_CURRENT_USER ,lpSubNsKey,0,KEY_ALL_ACCESS,&m_htKey); if (res == ERROR_SUCCESS) { //res = RegDeleteKey(m_htKey,lpSubNsKey); LONG status = SHDeleteKey( m_htKey,lpSubNsKey); RegCloseKey(m_htKey); } In the above code,the RegOpenKeyEx() is returning 0 means registery is getting opened but the SHDeleteKey() is returning 2 i.e. it's error code message is "The system cannot find the file specified". But the key name is available there in the registery. So,can you please suggest me what could be the problem?
With Regards Neeraj Sinha
You're passing the handle you got back from
RegOpenKeyEx
, which in effect means you're askingSHDeleteKey
to deleteHKEY_CURRENT_USER\SOFTWARE\N K Product\SOFTWARE\N K Product
, which presumably doesn't exist. Simply passHKEY_CURRENT_USER
as the first parameter toSHDeleteKey
, and don't bother callingRegOpenKeyEx
.Stability. What an interesting concept. -- Chris Maunder
-
You're passing the handle you got back from
RegOpenKeyEx
, which in effect means you're askingSHDeleteKey
to deleteHKEY_CURRENT_USER\SOFTWARE\N K Product\SOFTWARE\N K Product
, which presumably doesn't exist. Simply passHKEY_CURRENT_USER
as the first parameter toSHDeleteKey
, and don't bother callingRegOpenKeyEx
.Stability. What an interesting concept. -- Chris Maunder
Hi Mike Thanks a lot for your help.I got it and my problem got solved.
With Regards Neeraj Sinha