Java Jive
2023-10-15 17:00:38 UTC
I have created the BATch file appended below, which is intended to
provide a quick and painless way to change the screensaver and power
modes from their normal settings, Blank & Stay Awake, to a disabled
state, None and Presentation, and back again. This is easy enough to do
via the relevant dialog boxes, but is irritatingly fiddly because some
of the settings are under Personalisation, Screensaver and others under
Power, hence the desire for a quicker and simpler method.
The power setting change between Stay Awake and Presentation appears to
be working correctly, but the screensaver change is failing. If I run,
say ...
Screensave /0
... but then launch the control panel for the screensaver, the choice of
screensaver is correctly None, but the option "On resume, display logon
screen" is still checked and this means that the screen will still go to
the logon screen when the timer expires. Conversely if I clear the
option and do ...
Screensave /1
... and then launch the screensaver dialog again, the option remains
unchecked, which means that if the timer expires, or I hibernate the
machine, I'm not prompted for a password, which of course is insecure.
All online sources that I've read suggest that the following registry
settings should be enough to set the screensaver ...
With Blank screensaver:
[HKEY_CURRENT_USER\Control Panel\Desktop]
"ScreenSaveActive"="1"
"ScreenSaverIsSecure"="1"
"SCRNSAVE.EXE"="C:\\Windows\\system32\\scrnsave.scr"
With no screensaver:
[HKEY_CURRENT_USER\Control Panel\Desktop]
"ScreenSaveActive"="0"
"ScreenSaverIsSecure"="0"
ie: "SCRNSAVE.EXE" setting deleted
... and those are exactly what my BATch file sets. Further, a before
and after comparison of the entire registry after changing just the
screensaver lock setting manually suggests that the ScreenSaverIsSecure
setting is the only thing of any seeming relevance which is changed by
altering this setting:
[HKU\<ID>\Control Panel\Desktop]
"ScreenSaverIsSecure"="1"
; As expected, value changes to "0"
[HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32]
[HKU\<ID>\Software\Classes\Local
Settings\Software\Microsoft\Windows\Shell\Bags\584\ComDlgLegacy]
; Changes from saving the *.reg files not thought to be relevant
[HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist]
; Contents of key appear to be encrypted so hard to say whether
relevant, but name of key suggests not
[HKLM\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a03-9b1a-11d4-9123-0050047759bc}\24]
"ffffffffffffffffffffffffffffff02"=hex:01,00,00,00,41,c0,00,00,59,00,3f,03,ff,\
ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff
; Seems to be some sort of counter, '59' increased to '5a'
Now I'm wondering if it is necessary somehow to have the BATch file
alert the system, presumably the Explorer instance that is running the
Desktop, that the user registry hive has changed and it needs to reload
it. I could kill that Explorer instance, actually it would have to be
all Explorer instances, and relaunch Explorer, but doing that is way too
complicated for a "quicker and simpler" method, and actually pointless
because it would be easier just to continue altering the settings manually.
Anyone any ideas?
@ECHO OFF
Rem ScreenSave.bat
Rem ==============
Rem
Rem Program to turn on & off the screen saver and power screen blanking
options
Rem Non-empty string here or /1 leading parameter turns the screen saver
on and /0 off respectively
SET Switch="1"
Rem Non-empty string here or /D leading parameter gives debugging messages
SET Debug=""
:NextPar
IF /i "%1" EQU "/0" (
SET Switch="0"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/1" (
SET Switch="1"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/D" (
SET Debug="Y"
SHIFT
GOTO NextPar
)
IF %Switch%=="0" GOTO Off
:On
Rem Set screensaver to 'Blank'
ECHO Setting ScreenSaver to 'Blank'
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t
REG_SZ /d C:\Windows\system32\scrnsave.scr /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure
/t REG_SZ /d 1 /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t
REG_SZ /d 1 /f > NUL 2>&1
Rem Set power scheme to 'Stay Awake'
CALL :FindPowerGUID "Stay Awake" PName GUID
ECHO Setting Power Scheme to '%PName%'
powercfg /setactive %GUID%
GOTO Quit
:Off
Rem Set screensaver to 'None'
ECHO Setting ScreenSaver to 'None'
reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /f
/t REG_SZ /d 0 /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t
REG_SZ /d 0 /f > NUL 2>&1
Rem Set power scheme to 'Presentation'
CALL :FindPowerGUID "Presentation" PName GUID
ECHO Setting Power Scheme to '%PName%'
powercfg /setactive %GUID%
GOTO Quit
:FindPowerGUID
SETLOCAL EnableDelayedExpansion
for /f "usebackq tokens=1-4*" %%A in (`powercfg /list ^| find /i %1`) do (
IF %Debug% NEQ "" Echo %%D %%E
SET _Name=%%E
SET _GUID=%%D
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name:(=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name:)=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name: *=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
)
ENDLOCAL & (
IF %Debug% NEQ "" (
Echo SET %~2="%_Name%"
Echo SET %~3="%_GUID%" & Echo.
)
SET "%~2=%_Name%"
SET "%~3=%_GUID%"
)
SET _Name=
SET _GUID=
EXIT /B
:Quit
SET Switch=
SET Debug=
SET PName=
SET GUID=
ECHO.
provide a quick and painless way to change the screensaver and power
modes from their normal settings, Blank & Stay Awake, to a disabled
state, None and Presentation, and back again. This is easy enough to do
via the relevant dialog boxes, but is irritatingly fiddly because some
of the settings are under Personalisation, Screensaver and others under
Power, hence the desire for a quicker and simpler method.
The power setting change between Stay Awake and Presentation appears to
be working correctly, but the screensaver change is failing. If I run,
say ...
Screensave /0
... but then launch the control panel for the screensaver, the choice of
screensaver is correctly None, but the option "On resume, display logon
screen" is still checked and this means that the screen will still go to
the logon screen when the timer expires. Conversely if I clear the
option and do ...
Screensave /1
... and then launch the screensaver dialog again, the option remains
unchecked, which means that if the timer expires, or I hibernate the
machine, I'm not prompted for a password, which of course is insecure.
All online sources that I've read suggest that the following registry
settings should be enough to set the screensaver ...
With Blank screensaver:
[HKEY_CURRENT_USER\Control Panel\Desktop]
"ScreenSaveActive"="1"
"ScreenSaverIsSecure"="1"
"SCRNSAVE.EXE"="C:\\Windows\\system32\\scrnsave.scr"
With no screensaver:
[HKEY_CURRENT_USER\Control Panel\Desktop]
"ScreenSaveActive"="0"
"ScreenSaverIsSecure"="0"
ie: "SCRNSAVE.EXE" setting deleted
... and those are exactly what my BATch file sets. Further, a before
and after comparison of the entire registry after changing just the
screensaver lock setting manually suggests that the ScreenSaverIsSecure
setting is the only thing of any seeming relevance which is changed by
altering this setting:
[HKU\<ID>\Control Panel\Desktop]
"ScreenSaverIsSecure"="1"
; As expected, value changes to "0"
[HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32]
[HKU\<ID>\Software\Classes\Local
Settings\Software\Microsoft\Windows\Shell\Bags\584\ComDlgLegacy]
; Changes from saving the *.reg files not thought to be relevant
[HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist]
; Contents of key appear to be encrypted so hard to say whether
relevant, but name of key suggests not
[HKLM\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a03-9b1a-11d4-9123-0050047759bc}\24]
"ffffffffffffffffffffffffffffff02"=hex:01,00,00,00,41,c0,00,00,59,00,3f,03,ff,\
ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff
; Seems to be some sort of counter, '59' increased to '5a'
Now I'm wondering if it is necessary somehow to have the BATch file
alert the system, presumably the Explorer instance that is running the
Desktop, that the user registry hive has changed and it needs to reload
it. I could kill that Explorer instance, actually it would have to be
all Explorer instances, and relaunch Explorer, but doing that is way too
complicated for a "quicker and simpler" method, and actually pointless
because it would be easier just to continue altering the settings manually.
Anyone any ideas?
@ECHO OFF
Rem ScreenSave.bat
Rem ==============
Rem
Rem Program to turn on & off the screen saver and power screen blanking
options
Rem Non-empty string here or /1 leading parameter turns the screen saver
on and /0 off respectively
SET Switch="1"
Rem Non-empty string here or /D leading parameter gives debugging messages
SET Debug=""
:NextPar
IF /i "%1" EQU "/0" (
SET Switch="0"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/1" (
SET Switch="1"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/D" (
SET Debug="Y"
SHIFT
GOTO NextPar
)
IF %Switch%=="0" GOTO Off
:On
Rem Set screensaver to 'Blank'
ECHO Setting ScreenSaver to 'Blank'
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t
REG_SZ /d C:\Windows\system32\scrnsave.scr /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure
/t REG_SZ /d 1 /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t
REG_SZ /d 1 /f > NUL 2>&1
Rem Set power scheme to 'Stay Awake'
CALL :FindPowerGUID "Stay Awake" PName GUID
ECHO Setting Power Scheme to '%PName%'
powercfg /setactive %GUID%
GOTO Quit
:Off
Rem Set screensaver to 'None'
ECHO Setting ScreenSaver to 'None'
reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /f
NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure/t REG_SZ /d 0 /f > NUL 2>&1
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t
REG_SZ /d 0 /f > NUL 2>&1
Rem Set power scheme to 'Presentation'
CALL :FindPowerGUID "Presentation" PName GUID
ECHO Setting Power Scheme to '%PName%'
powercfg /setactive %GUID%
GOTO Quit
:FindPowerGUID
SETLOCAL EnableDelayedExpansion
for /f "usebackq tokens=1-4*" %%A in (`powercfg /list ^| find /i %1`) do (
IF %Debug% NEQ "" Echo %%D %%E
SET _Name=%%E
SET _GUID=%%D
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name:(=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name:)=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
SET _Name="!_Name: *=!"
SET _Name=!_Name:"=!
IF %Debug% NEQ "" Echo _Name="!_Name!"
)
ENDLOCAL & (
IF %Debug% NEQ "" (
Echo SET %~2="%_Name%"
Echo SET %~3="%_GUID%" & Echo.
)
SET "%~2=%_Name%"
SET "%~3=%_GUID%"
)
SET _Name=
SET _GUID=
EXIT /B
:Quit
SET Switch=
SET Debug=
SET PName=
SET GUID=
ECHO.
--
Fake news kills!
I may be contacted via the contact address given on my website:
www.macfh.co.uk
Fake news kills!
I may be contacted via the contact address given on my website:
www.macfh.co.uk