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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why do i can not delete Registry Keys ?

Why do i can not delete Registry Keys ?

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminlinuxhelpquestion
5 Posts 4 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.
  • G Offline
    G Offline
    gabbana
    wrote on last edited by
    #1

    Hello, i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks ! HKEY key; DWORD res; RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); wchar_t *data = L"C:\\cpack.exe e %1"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); data = L"CPACK"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); // deletes a key // RegUnLoadKey(HKEY_CLASSES_ROOT,L"CPACK"); RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK"); bye, gabbana

    L D H 3 Replies Last reply
    0
    • G gabbana

      Hello, i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks ! HKEY key; DWORD res; RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); wchar_t *data = L"C:\\cpack.exe e %1"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); data = L"CPACK"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); // deletes a key // RegUnLoadKey(HKEY_CLASSES_ROOT,L"CPACK"); RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK"); bye, gabbana

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You cannot delete a registry key if subkeys exist. If you were successful with creating the key and subkeys then you should be able to delete them as well. RegDeleteKey will fail with ERROR_ACCESS_DENIED if a subkey exists. You need to implement a recursive deletion[^]. Best Wishes, -David Delaune

      G 1 Reply Last reply
      0
      • L Lost User

        You cannot delete a registry key if subkeys exist. If you were successful with creating the key and subkeys then you should be able to delete them as well. RegDeleteKey will fail with ERROR_ACCESS_DENIED if a subkey exists. You need to implement a recursive deletion[^]. Best Wishes, -David Delaune

        G Offline
        G Offline
        gabbana
        wrote on last edited by
        #3

        ahh okay now it works fine. Thanks.

        1 Reply Last reply
        0
        • G gabbana

          Hello, i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks ! HKEY key; DWORD res; RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); wchar_t *data = L"C:\\cpack.exe e %1"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); data = L"CPACK"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); // deletes a key // RegUnLoadKey(HKEY_CLASSES_ROOT,L"CPACK"); RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK"); bye, gabbana

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          gabbana wrote:

          Whats going wrong there?

          What's going on is that you are not checking for errors. From MSDN: If RegDeleteKey() fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage() function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • G gabbana

            Hello, i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks ! HKEY key; DWORD res; RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); wchar_t *data = L"C:\\cpack.exe e %1"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res); data = L"CPACK"; RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR)); RegCloseKey(key); // deletes a key // RegUnLoadKey(HKEY_CLASSES_ROOT,L"CPACK"); RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK"); bye, gabbana

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            And see A Registry Class[^]. ;)

            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