Disable Windows XP Screen Saver through Policies

4 02 2011

Today I had to fix a problem on a Windows XP Embedded system where it was not possible to disable the Windows screensaver. The Windows XP Embedded device has a custom (touchscreen) GUI for modifying the screensaver timeout and enabling/disabling the screensaver. Enabling/disabling the screensaver was implemented through the following Win32 API call:

SetSystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0 | 1, null, SPIF_UPDATEINIFILE| SPIF_SENDCHANGE);

This worked on an Windows XP Professional development system, but it failed to disable the screensaver on the Windows XP Embedded target device. The API call succeeded, but the screensaver was still activated by the system.

During analysis of this problem I opened the screensaver configuration page (desk.cpl, Screen Saver tab) and found that the screensaver selection dropdown combobox was disabled. My first idea was that this dropdown was disabled because there was only a single screensaver (.scr file) installed. I checked the C:\Windows\system32 directory for *.scr files and found that there were two screensavers available. So why was the dropdown combobox disabled?

Googling for “screen saver selection disabled” revealed this very helpful blog post: Screen Saver Selection is Grayed Out or Disabled

From this blog post I learned that you can control (overwrite!) the availability of screensaver options through system policies stored in the following registry key:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop

If you add a ScreenSaveActive=1 value here, this forces the screensaver to be always active, no matter what API the user calls. (You can also e. g. enforce one specific screensaver by adding a SCRNSAVE.EXE=<path> value.)

Note: When the ScreenSaveActive=1 policy is set, the ScreenSaveActive entry at

HKEY_CURRENT_USER\Control Panel\Desktop

is always 0 and ignored.

Advertisements




Enable/disable hibernation programmatically

20 05 2009

Die Hibernate-Funktionalität lässt sich interaktiv über das „Power Options“ Control Panel Applet (powercfg.cpl) ein-/ausschalten.

Die Hibernate-Funktionalität lässt sich folgendermaßen per Kommdozeile  ein-/ausschalten:

powercfg.exe /H ON|OFF

Um die Hibernate-Funktion per Programm (API) ein-/auszuschalten, ist die Win32 API Funktion CallNtPowerInformation mit dem Parameter InformationLevel=10 (SystemReserveHiberFile) zu verwenden. Der Parameter lpInputBuffer muss dazu auf einen bool’schen Wert zeigen, für die Länge von nInputBufferSize genügt 1.

Beispiel:

bool bOnOff = true;
CallNtPowerInformation(10, &bOnOff, sizeof(bOnOff), NULL, 0);

Hinweis: Das kurzzeitige Aus- und wieder Einschalten der Hibernate-Funktion kann verwendet werden, um zu Verhindern, dass Windows nach dem Aufwecken aus dem Hibernate-Zustand nach 5 Minuten wieder schlafen geht wenn keine Benutzereingaben (Maus, Tastatur) erfolgen. Dieses „Feature“ ist hier beschrieben.