How to access HKEY_CURRENT_USER from local system account?
-
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.
-
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.
Two quick things - first
SystemParametersInfo(...)
does not use C++ types, so you should be passing the address of aBOOL
(anint
, or 4-bytes under 32-bit MS), not abool
(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!) -
Two quick things - first
SystemParametersInfo(...)
does not use C++ types, so you should be passing the address of aBOOL
(anint
, or 4-bytes under 32-bit MS), not abool
(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!)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.
-
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.
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
-
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
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.