Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem in deleting the windows registery key and it's sub key

Problem in deleting the windows registery key and it's sub key

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neeraj Sinha
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • N 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

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      You're passing the handle you got back from RegOpenKeyEx, which in effect means you're asking SHDeleteKey to delete HKEY_CURRENT_USER\SOFTWARE\N K Product\SOFTWARE\N K Product, which presumably doesn't exist. Simply pass HKEY_CURRENT_USER as the first parameter to SHDeleteKey, and don't bother calling RegOpenKeyEx.

      Stability. What an interesting concept. -- Chris Maunder

      N 1 Reply Last reply
      0
      • M Mike Dimmick

        You're passing the handle you got back from RegOpenKeyEx, which in effect means you're asking SHDeleteKey to delete HKEY_CURRENT_USER\SOFTWARE\N K Product\SOFTWARE\N K Product, which presumably doesn't exist. Simply pass HKEY_CURRENT_USER as the first parameter to SHDeleteKey, and don't bother calling RegOpenKeyEx.

        Stability. What an interesting concept. -- Chris Maunder

        N Offline
        N Offline
        Neeraj Sinha
        wrote on last edited by
        #3

        Hi Mike Thanks a lot for your help.I got it and my problem got solved.

        With Regards Neeraj Sinha

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups