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. How to work with the registry from a limited account in windows xp

How to work with the registry from a limited account in windows xp

Scheduled Pinned Locked Moved C / C++ / MFC
helpwindows-admintutorialquestion
7 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.
  • J Offline
    J Offline
    jluis_hdezg
    wrote on last edited by
    #1

    Right now I run the code with a administrator user and works just fine, but when I do it with a limited account user the first time works just fine but the second time gives me this error: ERROR_ALREADY_EXISTS = Cannot Create a file when that file already exists. This is what I'm doing: 1.- LogonUser; with the administrator account. 2.- ImpersonateLoggedOnUser 3.- RegOpenKeyEx Does anyone knows how to work this around? Any help is greatly apreciated. Thanks... JH

    S 1 Reply Last reply
    0
    • J jluis_hdezg

      Right now I run the code with a administrator user and works just fine, but when I do it with a limited account user the first time works just fine but the second time gives me this error: ERROR_ALREADY_EXISTS = Cannot Create a file when that file already exists. This is what I'm doing: 1.- LogonUser; with the administrator account. 2.- ImpersonateLoggedOnUser 3.- RegOpenKeyEx Does anyone knows how to work this around? Any help is greatly apreciated. Thanks... JH

      S Offline
      S Offline
      skornel
      wrote on last edited by
      #2

      A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.

      J D 2 Replies Last reply
      0
      • S skornel

        A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.

        J Offline
        J Offline
        jluis_hdezg
        wrote on last edited by
        #3

        First of all, thanks...skornel. I understand your answer, however; I am trying to enable and disable the USB Ports (HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR), which is already by default. It's not something that I created my self. Is there a way to modify this key val when the program is running with a limited account?. Thanks. Regards, JH

        S 1 Reply Last reply
        0
        • J jluis_hdezg

          First of all, thanks...skornel. I understand your answer, however; I am trying to enable and disable the USB Ports (HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR), which is already by default. It's not something that I created my self. Is there a way to modify this key val when the program is running with a limited account?. Thanks. Regards, JH

          S Offline
          S Offline
          skornel
          wrote on last edited by
          #4

          I don't know of any way to change any value in HKLM from a normal user account that does not have admin rights. The only thing I can think of would be for someone with admin rights, to change the permissions on the HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services to allow modify rights to a particular group and then be sure the user is in that group. That may work but I've not tried it. 'Permissions...' is in the right-button context menu in RegEdit.

          1 Reply Last reply
          0
          • S skornel

            A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.

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

            skornel wrote:

            A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM.

            True, but what does all of this have to do with ERROR_ALREADY_EXISTS?


            "A good athlete is the result of a good and worthy opponent." - David Crow

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

            O 1 Reply Last reply
            0
            • D David Crow

              skornel wrote:

              A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM.

              True, but what does all of this have to do with ERROR_ALREADY_EXISTS?


              "A good athlete is the result of a good and worthy opponent." - David Crow

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

              O Offline
              O Offline
              OmurOlmez
              wrote on last edited by
              #6

              It is because, actually you change value in HKCU not in HKLM. You said, it works for first time and it fails for second time. Well, it works first because there is no key exist before and you have write access. So this is HKCU. It fails second because, you already wrote it when your first time. Probably you do not check result of ImpersonateLoggedOnUser function.

              modified on Thursday, May 14, 2009 2:42 AM

              D 1 Reply Last reply
              0
              • O OmurOlmez

                It is because, actually you change value in HKCU not in HKLM. You said, it works for first time and it fails for second time. Well, it works first because there is no key exist before and you have write access. So this is HKCU. It fails second because, you already wrote it when your first time. Probably you do not check result of ImpersonateLoggedOnUser function.

                modified on Thursday, May 14, 2009 2:42 AM

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

                Perhaps you meant to reply to the OP, but after 2 years he may have moved on. :rolleyes:

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                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