6

In my service I need to issue a "refresh" after changing the logon screensaver timeout. While doing research, I kept finding references to UpdatePerUserSystemParameters API. This API seems to be present in user32.dll but I can't find out what exact does it do? (Well, besides literally reading its name.) Any suggestions?

c00000fd
  • 20,994
  • 29
  • 177
  • 400

1 Answers1

7

It was/is(?) a way for forcing the OS to refresh certain system settings by re-reading the relevant registry keys. In particular for colour schemes or desktop backgrounds. So it meant that you could change e.g. the Windows desktop wallpaper by merging a .reg file into the registry and then executing UpdatePerUserSystemParameters from user32.dll to make it read and apply the changed entries.

As the post you linked dictates, the SystemParametersInfo function is the correct way to change system parameters, and this must be done programatically rather than via a registry hack and a forced refresh from a .bat file.

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • Unfortunately calling `SystemParametersInfo` from a system service for my needs results in the error 1459, or ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION, so it doesn't do me a thing. (I need to use it to change the logon screensaver.) On the side note, by any chance you don't know what parameters was `UpdatePerUserSystemParameters` supposed to be called with? – c00000fd Jan 13 '14 at 08:42
  • @c00000fd Ok, I skipped the bit about a service, sorry - just answered what was asked. I guess you are using `SPIF_SENDCHANGE` then? If so, do you get the same error if you just supply zero for that parameter? I guess you tried "Allow service to interact with desktop" option? – Roger Rowland Jan 13 '14 at 13:12
  • Yeah, I tried all the possible flags -- still the same error. Also when I make my service to "Allow service to interact with desktop" the `SystemParametersInfo` API succeeds but it makes no change to the actual logon screensaver parameters. It must be running in a different desktop in that case... – c00000fd Jan 14 '14 at 09:02
  • 1
    @c00000fd Yes I guess it's the session isolation that's the problem. [This post](http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/4088f4ed-7a7a-422d-ba83-1381a1542514/systemparametersinfo-do-not-work-on-windows7-when-the-app-is-a-service?forum=windowssecurity) and [this post](http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/31bfa13d-982b-4b1a-bff3-2761ade5214f/calling-createprocessasuser-from-service?forum=windowssecurity) may have some useful info but they were Vista and I have a vague memory that session isolation was tightened in Win7 upwards. – Roger Rowland Jan 14 '14 at 09:18
  • Thanks. Unfortunately I can't call `WTSGetActiveConsoleSessionId` and later `WTSQueryUserToken` to obtain the logged on user token, since, well... I don't have any. – c00000fd Jan 14 '14 at 09:46
  • Just tried it. `WTSGetActiveConsoleSessionId` returned a valid session ID, but then `WTSQueryUserToken` failed with the error code `ERROR_NO_TOKEN`. – c00000fd Jan 14 '14 at 09:55
  • @c00000fd I see. I think I can feel another question coming on .... why not close this one down and ask about using `SystemParametersInfo` via a service instead? – Roger Rowland Jan 14 '14 at 10:04
  • 1
    Just a quick update. I was able to resolve it. Check the other thread: http://stackoverflow.com/q/21085199/843732 and thanks for your help! – c00000fd Jan 16 '14 at 09:42