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 access HKEY_CURRENT_USER from local system account?

How to access HKEY_CURRENT_USER from local system account?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionwindows-admintutorial
5 Posts 3 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.
  • K Offline
    K Offline
    khb
    wrote on last edited by
    #1

    Hi together, I have a big problem. I hope somebody can help me: I implemented a service that runs under the local system account and checks if any screen blanker is activated. I use the following code:

    bool result = false;
    SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (LPVOID) &result, 0);

    This works fine on Win XP, but on Win 2000 the function always return true. It is a known bug according to article number 318781 on MSDN. The suggested workaround is to look for the entry "SCRNSAVE.EXE" under the registry key "HKCU\Control Panel\Desktop" using the following two lines:

    RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ, &hKeyScrSave);
    RegQueryValueEx(hKeyScrSave, "SCRNSAVE.EXE", NULL, NULL, (LPBYTE) szData, &dwData);

    Now the problem arises: As my service runs under the local system account, access to "HKEY_CURRENT_USER" is redirected to "HKEY_USERS\.DEFAULT". X| So the result refers to the logon screen saver, which is (usually) always activated. But I only want this result if no user in logged in. Therefore my question: Does anybody has a solution, how to check if a screen saver is active under 2000 like SystemParametersInfo(SPI_GETSCREENSAVEACTIVE) does it for XP? An idea how to access data under "HKEY_CURRENT_USER" from the local system account would also be very valuable for me. Thank you very much for any hints, Marcus.

    J D 2 Replies Last reply
    0
    • K khb

      Hi together, I have a big problem. I hope somebody can help me: I implemented a service that runs under the local system account and checks if any screen blanker is activated. I use the following code:

      bool result = false;
      SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (LPVOID) &result, 0);

      This works fine on Win XP, but on Win 2000 the function always return true. It is a known bug according to article number 318781 on MSDN. The suggested workaround is to look for the entry "SCRNSAVE.EXE" under the registry key "HKCU\Control Panel\Desktop" using the following two lines:

      RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ, &hKeyScrSave);
      RegQueryValueEx(hKeyScrSave, "SCRNSAVE.EXE", NULL, NULL, (LPBYTE) szData, &dwData);

      Now the problem arises: As my service runs under the local system account, access to "HKEY_CURRENT_USER" is redirected to "HKEY_USERS\.DEFAULT". X| So the result refers to the logon screen saver, which is (usually) always activated. But I only want this result if no user in logged in. Therefore my question: Does anybody has a solution, how to check if a screen saver is active under 2000 like SystemParametersInfo(SPI_GETSCREENSAVEACTIVE) does it for XP? An idea how to access data under "HKEY_CURRENT_USER" from the local system account would also be very valuable for me. Thank you very much for any hints, Marcus.

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      Two quick things - first SystemParametersInfo(...) does not use C++ types, so you should be passing the address of a BOOL (an int, or 4-bytes under 32-bit MS), not a bool (1-byte under 32-bit MS).    Second, I am pretty sure that screen savers run on a separate desktop, the "screen saver desktop".  Search MSDN for information on Window Stations and Desktops for more information.    If I am correct, you might be able to determine which desktop is active, and from that determine if a screen saver is running.    Peace! -=- James


      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      DeleteFXPFiles & CheckFavorites (Please rate this post!)

      K 1 Reply Last reply
      0
      • J James R Twine

        Two quick things - first SystemParametersInfo(...) does not use C++ types, so you should be passing the address of a BOOL (an int, or 4-bytes under 32-bit MS), not a bool (1-byte under 32-bit MS).    Second, I am pretty sure that screen savers run on a separate desktop, the "screen saver desktop".  Search MSDN for information on Window Stations and Desktops for more information.    If I am correct, you might be able to determine which desktop is active, and from that determine if a screen saver is running.    Peace! -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        K Offline
        K Offline
        khb
        wrote on last edited by
        #3

        Hi James, thank you very much for your reply! Concerning the bool/BOOL issue: I'm actually using a BOOL. In my message, however, I cut & pasted the code from MSDN, which seems to contain several bugs/typos :( Anyway, thanks for the hint. Concerning the desktop issue: I think you are right. Some time ago I've read that the screen saver runs on another desktop. So I'll dig into that again ;) Thank you again, Marcus.

        1 Reply Last reply
        0
        • K khb

          Hi together, I have a big problem. I hope somebody can help me: I implemented a service that runs under the local system account and checks if any screen blanker is activated. I use the following code:

          bool result = false;
          SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (LPVOID) &result, 0);

          This works fine on Win XP, but on Win 2000 the function always return true. It is a known bug according to article number 318781 on MSDN. The suggested workaround is to look for the entry "SCRNSAVE.EXE" under the registry key "HKCU\Control Panel\Desktop" using the following two lines:

          RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ, &hKeyScrSave);
          RegQueryValueEx(hKeyScrSave, "SCRNSAVE.EXE", NULL, NULL, (LPBYTE) szData, &dwData);

          Now the problem arises: As my service runs under the local system account, access to "HKEY_CURRENT_USER" is redirected to "HKEY_USERS\.DEFAULT". X| So the result refers to the logon screen saver, which is (usually) always activated. But I only want this result if no user in logged in. Therefore my question: Does anybody has a solution, how to check if a screen saver is active under 2000 like SystemParametersInfo(SPI_GETSCREENSAVEACTIVE) does it for XP? An idea how to access data under "HKEY_CURRENT_USER" from the local system account would also be very valuable for me. Thank you very much for any hints, Marcus.

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

          khb wrote:

          SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (LPVOID) &result, 0);

          I think you want to check SPI_GETSCREENSAVERRUNNING instead.

          khb wrote:

          Now the problem arises: As my service runs under the local system account, access to "HKEY_CURRENT_USER" is redirected to "HKEY_USERS\.DEFAULT".

          See MSDN article Q168877 for an example.


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          K 1 Reply Last reply
          0
          • D David Crow

            khb wrote:

            SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (LPVOID) &result, 0);

            I think you want to check SPI_GETSCREENSAVERRUNNING instead.

            khb wrote:

            Now the problem arises: As my service runs under the local system account, access to "HKEY_CURRENT_USER" is redirected to "HKEY_USERS\.DEFAULT".

            See MSDN article Q168877 for an example.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            K Offline
            K Offline
            khb
            wrote on last edited by
            #5

            Hi David, I think that what I posted was correct. I want to check if a user has "installed" a screen saver so that I can expect that there is a change that it will start running somewhen. Anyway, I check if it is actually running, too. The howto on Q168877 seems to be exactly what I was looking for, great! Thank you, Marcus.

            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