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. RegOpenKeyEx gets error 5 (ERROR_ACCESS_DENIED)

RegOpenKeyEx gets error 5 (ERROR_ACCESS_DENIED)

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
10 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.
  • M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #1

    I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege): HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture and I keep getting the error code 5 (ERROR_ACCESS_DENIED). I followed this solution[^] to adjust the token privilege. This step succeeded, but then RegOpenKeyEx still returned ERROR_ACCESS_DENIED. What else should I do to access this key? Thanks in advance.

    Maxwell Chen

    C S 2 Replies Last reply
    0
    • M Maxwell Chen

      I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege): HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture and I keep getting the error code 5 (ERROR_ACCESS_DENIED). I followed this solution[^] to adjust the token privilege. This step succeeded, but then RegOpenKeyEx still returned ERROR_ACCESS_DENIED. What else should I do to access this key? Thanks in advance.

      Maxwell Chen

      C Offline
      C Offline
      Cool_Dev
      wrote on last edited by
      #2

      Are you on Windows-7? then see this thread.. http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/073349b1-0f29-41ef-aaab-dbb262d52457[^]

      M 1 Reply Last reply
      0
      • M Maxwell Chen

        I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege): HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture and I keep getting the error code 5 (ERROR_ACCESS_DENIED). I followed this solution[^] to adjust the token privilege. This step succeeded, but then RegOpenKeyEx still returned ERROR_ACCESS_DENIED. What else should I do to access this key? Thanks in advance.

        Maxwell Chen

        S Offline
        S Offline
        ShilpiP
        wrote on last edited by
        #3

        Hi Maxwell, Its not an answer but I have one doubt. Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista. If my application is not lauched with admin priviledge than i get access denied error else it is working fine.

        I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

        M 1 Reply Last reply
        0
        • C Cool_Dev

          Are you on Windows-7? then see this thread.. http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/073349b1-0f29-41ef-aaab-dbb262d52457[^]

          M Offline
          M Offline
          Maxwell Chen
          wrote on last edited by
          #4

          Hi Cool_Dev, I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right? Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.

          Maxwell Chen

          C 1 Reply Last reply
          0
          • S ShilpiP

            Hi Maxwell, Its not an answer but I have one doubt. Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista. If my application is not lauched with admin priviledge than i get access denied error else it is working fine.

            I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #5

            Hi Shilpi,

            Shilpi Boosar wrote:

            Are you sure that your application is launched with admin priviledge ??

            I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command: MyService.exe -r to setup and start the service.

            Maxwell Chen

            Richard Andrew x64R 1 Reply Last reply
            0
            • M Maxwell Chen

              Hi Cool_Dev, I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right? Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.

              Maxwell Chen

              C Offline
              C Offline
              Cool_Dev
              wrote on last edited by
              #6

              That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument. Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.

              M 1 Reply Last reply
              0
              • M Maxwell Chen

                Hi Shilpi,

                Shilpi Boosar wrote:

                Are you sure that your application is launched with admin priviledge ??

                I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command: MyService.exe -r to setup and start the service.

                Maxwell Chen

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #7

                I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.

                The difficult we do right away... ...the impossible takes slightly longer.

                M S 2 Replies Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.

                  The difficult we do right away... ...the impossible takes slightly longer.

                  M Offline
                  M Offline
                  Maxwell Chen
                  wrote on last edited by
                  #8

                  Richard Andrew x64 wrote:

                  Open Task Manager, find the process that represents your service and check what user account it is running under.

                  Hi Richard, My service is running under the name SYSTEM. (The logon session user account is "user".)

                  Maxwell Chen

                  1 Reply Last reply
                  0
                  • C Cool_Dev

                    That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument. Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.

                    M Offline
                    M Offline
                    Maxwell Chen
                    wrote on last edited by
                    #9

                    Cool_Dev wrote:

                    That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument. Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.

                    Hi Cool_Dev, 1) The name KEY_WOW64_64KEY is not defined in VC++ 6. So I did not add it since the compiler said "undeclared identifier". 2) RegOpenKeyEx returns value 0 in the PHKEY argument. 3) I have been using KEY_ALL_ACCESS all the time. 4) During run-time seen on the debugger, ERROR_ACCESS_DENIED is 0x0005 and ERROR_CANTWRITE is 0x03F5. Please refer to the screenshot[^] on VC++2005 remote debugger.

                    Maxwell Chen

                    1 Reply Last reply
                    0
                    • Richard Andrew x64R Richard Andrew x64

                      I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.

                      The difficult we do right away... ...the impossible takes slightly longer.

                      S Offline
                      S Offline
                      ShilpiP
                      wrote on last edited by
                      #10

                      Nops if He open command prompt as "run as admin" mode and run application than it means that its application is also run as admin mode.

                      I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

                      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