#StandWithUkraine

Toggling screensaver on/off with AutoIt

AutoIt Karl of AskTheAdmin had recently posted answer to question how to create shortcuts for enabling/disabling screensaver. Method is using only native Windows tools so is somewhat bulky with four files required – two with registry settings and two shortcuts.

Controlling this (or any other) registry setting can be easily scripted in AutoIt.

Basically we need to read registry value and switch it to opposite.

$key="HKEY_CURRENT_USER\Control Panel\Desktop"
$value="ScreenSaveActive"
If Number(RegRead($key, $value)) Then
RegWrite($key, $value, "REG_SZ", 0)
Else
RegWrite($key, $value, "REG_SZ", 1)
EndIf
Exit
  • $key and $value are variables that describe registry setting we are dealing with;
  • RegRead and RegWrite handle reading and writing that setting;
  • Number converts string (text) we read from registry to number so we can process it like True (1) or False (0) and act accordingly.

Note that this is not very important setting and taking a look at screensaver properties usually sets it to 1 without asking user.

As always I am keeping it simple but it can be easily expanded. For example if your media player doesn’t support disabling screensaver while playing – you can modify script so it detects running player and disables screensaver.

Script https://www.rarst.net/script/togglescreensaver.au3

Related Posts

1 Comments

  • tobamai #

    $key="HKEY_CURRENT_USER\Control Panel\Desktop" $value="ScreenSaveActive" $i=Number(RegRead($key, $value)) RegWrite($key, $value, "REG_SZ", 1-$i) Exit