Search code examples
c#systemscreensaver

How to change screen saver timeout and screensaverissecure in windows using c#


How to change screen saver timeout and screensaverissecure using user32.dll for the current user (or) any other users in windows through C# code, as my application is running with SYSTEM privileges in the background process.

When we change the value of this registry using c# or scripting HKEY_CURRENT_USER\Control Panel\Desktop\ScreensaverTimeout and HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaverIsSecure this effect is showing only after reboot of machine.

when we change the registry value using c# code with SYSTEM privileges those changes are not effecting with new values.


Solution

  • Q1: ...this effect is showing only after reboot of machine:

    After updating registry, you can call UpdatePerUserSystemParameters to force Windows to reread the configuration from the registry (so the update takes effect immediately).

    rundll32.exe user32.dll, UpdatePerUserSystemParameters
    

    Q2: ...with SYSTEM privileges those changes are not effecting with new values:

    You need to launch a new process which is running in the same session as the current log on user, and update the registry values from the new process. This is good question to get started.