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. Can't read certain registry keys

Can't read certain registry keys

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comwindows-admin
10 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.
  • D Offline
    D Offline
    Daniel Tak M
    wrote on last edited by
    #1

    Hi everyone, I am currently trying to read the following registry key in one of my programs:

    HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName

    I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)

    http://www.renderpal.com http://www.shoran.de

    Richard Andrew x64R 2 Replies Last reply
    0
    • D Daniel Tak M

      Hi everyone, I am currently trying to read the following registry key in one of my programs:

      HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName

      I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)

      http://www.renderpal.com http://www.shoran.de

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

      Daniel 'Tak' M. wrote:

      as it works fine with other keys.

      Daniel 'Tak' M. wrote:

      (other keys also don't work).

      Which is it?

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

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

        Daniel 'Tak' M. wrote:

        as it works fine with other keys.

        Daniel 'Tak' M. wrote:

        (other keys also don't work).

        Which is it?

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

        D Offline
        D Offline
        Daniel Tak M
        wrote on last edited by
        #3

        The code works with other keys which are _not_ in Winlogon. Like HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports (read COM1:, retrieved the correct string).

        http://www.renderpal.com http://www.shoran.de

        Richard Andrew x64R 1 Reply Last reply
        0
        • D Daniel Tak M

          The code works with other keys which are _not_ in Winlogon. Like HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports (read COM1:, retrieved the correct string).

          http://www.renderpal.com http://www.shoran.de

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

          OK. You might want to post the code you are using. Maybe we can see something wrong with it.

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

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

            OK. You might want to post the code you are using. Maybe we can see something wrong with it.

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

            D Offline
            D Offline
            Daniel Tak M
            wrote on last edited by
            #5

            Here it is (pretty straightforward):

            HKEY hKey;
            
            if (RegCreateKeyEx(HKEY\_LOCAL\_MACHINE, "SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon", 0, NULL, REG\_OPTION\_NON\_VOLATILE, KEY\_READ, NULL, &hKey, NULL) == ERROR\_SUCCESS)
            {
            	BYTE   lpBuffer\[1024\];
            	DWORD  dwType;
            	DWORD  dwBufferSize = 1024;
            
            	if (RegQueryValueEx(hKey, "DefaultUserName", 0, &dwType, lpBuffer, &dwBufferSize) == ERROR\_SUCCESS)
            	{
            		...
            	}
            }
            

            The query succeeds, but the buffer is simply empty (though the setting isn't); if I change Winlogon to "Ports" and the key name to "COM1:", I get the correct value.

            http://www.renderpal.com http://www.shoran.de

            1 Reply Last reply
            0
            • D Daniel Tak M

              Hi everyone, I am currently trying to read the following registry key in one of my programs:

              HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName

              I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)

              http://www.renderpal.com http://www.shoran.de

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

              Are you working with the 32 or 64 bit version of Windows?

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

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

                Are you working with the 32 or 64 bit version of Windows?

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

                D Offline
                D Offline
                Daniel Tak M
                wrote on last edited by
                #7

                64 bit; the program is 32 bit, though.

                http://www.renderpal.com http://www.shoran.de

                Richard Andrew x64R 1 Reply Last reply
                0
                • D Daniel Tak M

                  64 bit; the program is 32 bit, though.

                  http://www.renderpal.com http://www.shoran.de

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

                  That might be the problem. Try calling RegCreateKeyEx as such:

                  RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WOW64_64KEY, NULL, &hKey, NULL)

                  Use the KEY_WOW64_64KEY flag to indicate that you want to open the 64-bit view of the key.

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

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

                    That might be the problem. Try calling RegCreateKeyEx as such:

                    RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WOW64_64KEY, NULL, &hKey, NULL)

                    Use the KEY_WOW64_64KEY flag to indicate that you want to open the 64-bit view of the key.

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

                    D Offline
                    D Offline
                    Daniel Tak M
                    wrote on last edited by
                    #9

                    That did it! You really saved my day, Richard. My MSDN docs don't include that extra flag (VS 2005 still...), so I didn't know about it.

                    http://www.renderpal.com http://www.shoran.de

                    Richard Andrew x64R 1 Reply Last reply
                    0
                    • D Daniel Tak M

                      That did it! You really saved my day, Richard. My MSDN docs don't include that extra flag (VS 2005 still...), so I didn't know about it.

                      http://www.renderpal.com http://www.shoran.de

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

                      Glad I could help. :-D

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

                      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