Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users know your home telephone number.


computers / alt.windows7.general / Re: Setting screensaver from command-line [SOLVED]

SubjectAuthor
* Setting screensaver from command-lineJava Jive
+* Re: Setting screensaver from command-lineJJ
|+* Re: Setting screensaver from command-lineJava Jive
||`* Re: Setting screensaver from command-lineJava Jive
|| `* Re: Setting screensaver from command-lineJJ
||  `- Re: Setting screensaver from command-lineJava Jive
|`- Re: Setting screensaver from command-lineZaidy036
+- Re: Setting screensaver from command-lineJava Jive
`- Re: Setting screensaver from command-line [SOLVED]Java Jive

1
Setting screensaver from command-line

<ugh5rq$k0fu$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7177&group=alt.windows7.general#7177

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!news.bbs.nz!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Setting screensaver from command-line
Date: Sun, 15 Oct 2023 18:00:38 +0100
Organization: A noiseless patient Spider
Lines: 183
Message-ID: <ugh5rq$k0fu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 15 Oct 2023 17:00:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7cc5d02d748657bb206e19cbe119ff41";
logging-data="655870"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sRj939Mzg3m9kV54+hViVG02/Ouzt17Q="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:Zkw9/OFt71nFTPS7FXg5ZAhpuJs=
Content-Language: en-GB
X-Mozilla-News-Host: news://news.eternal-september.org
 by: Java Jive - Sun, 15 Oct 2023 17:00 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
> 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

Re: Setting screensaver from command-line

<ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7178&group=alt.windows7.general#7178

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jj4pub...@outlook.com (JJ)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Mon, 16 Oct 2023 15:33:55 +0700
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>
References: <ugh5rq$k0fu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="3ca84ba666492c2c6b48ef495d9faa48";
logging-data="1371694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19o1Kqn8gittYmBFWjiNNGFNDYeFyUwS7U="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:Q1MCDKSCkQSG82rl3cprTXIFTpY=
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Mon, 16 Oct 2023 08:33 UTC

On Sun, 15 Oct 2023 18:00:38 +0100, Java Jive wrote:
> 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]

Registry data changes in `HKEY_CURRENT_USER\Control Panel` can be notified
by broadcasting WM_SETTINGCHANGE window message, but batch file alone
doesn't have that capability. A separate tool is neeed. e.g. AutoHotkey,
AutoIt, PowerShell, etc.

> [HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32]

Notification of changes of registry data in this key is not needed, as they
are always re-read when the dialog is needed.

> [HKU\<ID>\Software\Classes\Local
> Settings\Software\Microsoft\Windows\Shell\Bags\584\ComDlgLegacy]

Explorer doesn't re-read registry data under
`HKU\<ID>\Software\Classes\Local
Settings\Software\Microsoft\Windows\Shell\Bags` each time a folder view is
needed. Even if there was registry changes window message notification. Only
system restart, user re-login, or EXPLORER.EXE process restart will re-read
them.

Same thing applies to registry data in
`HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist`
key. PS: it's used to cache things. See: Nirsoft UserAssistView tool.

> [HKLM\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a03-9b1a-11d4-9123-0050047759bc}\24]

NSI service registry data changes is not notifiable. The service will need
to be restarted for changes to take effect. However, the service is needed
by various other network related services. i.e. at least these:

Browser, Dhcp, Dnscache, HomeGroupProvider, iphlpsvc, LanmanWorkstation,
Netlogon, Netman, netprofm, NlaSvc, SessionEnv, SharedAccess,
WinHttpAutoProxySvc, WwanSvc

Some of above services can't be restarted and the system will need to be
restarted in order for the registry changes to take effect.

....

So, since at least one registry data changes need a system restart. It's
best to simply give a warning to the user that the registry changes will not
have any effect until the system is restarted.

Re: Setting screensaver from command-line

<ugj64v$1c8p4$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7179&group=alt.windows7.general#7179

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Mon, 16 Oct 2023 12:17:48 +0100
Organization: A noiseless patient Spider
Lines: 94
Message-ID: <ugj64v$1c8p4$1@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
<ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Oct 2023 11:17:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="070c879eabde6028cbcf0dde88c0150f";
logging-data="1450788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TFdV7O+Kfhi9fMDsmMkG89D6bnUPqwWc="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:KEZjtg/7+ER+a01ED1My7f/mtY4=
In-Reply-To: <ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>
Content-Language: en-GB
 by: Java Jive - Mon, 16 Oct 2023 11:17 UTC

On 16/10/2023 09:33, JJ wrote:
>
> On Sun, 15 Oct 2023 18:00:38 +0100, Java Jive wrote:
>>
>> 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">
>
> Registry data changes in `HKEY_CURRENT_USER\Control Panel` can be notified
> by broadcasting WM_SETTINGCHANGE window message, but batch file alone
> doesn't have that capability. A separate tool is neeed. e.g. AutoHotkey,
> AutoIt, PowerShell, etc.

Thanks, I'll investigate that further.

>> [HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32]
>
> Notification of changes of registry data in this key is not needed, as they
> are always re-read when the dialog is needed.
>
>> [HKU\<ID>\Software\Classes\Local
>> Settings\Software\Microsoft\Windows\Shell\Bags\584\ComDlgLegacy]
>
> Explorer doesn't re-read registry data under
> `HKU\<ID>\Software\Classes\Local
> Settings\Software\Microsoft\Windows\Shell\Bags` each time a folder view is
> needed. Even if there was registry changes window message notification. Only
> system restart, user re-login, or EXPLORER.EXE process restart will re-read
> them.
>
> Same thing applies to registry data in
> `HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist`
> key. PS: it's used to cache things. See: Nirsoft UserAssistView tool.
>
>> [HKLM\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a03-9b1a-11d4-9123-0050047759bc}\24]
>
> NSI service registry data changes is not notifiable. The service will need
> to be restarted for changes to take effect. However, the service is needed
> by various other network related services. i.e. at least these:
>
> Browser, Dhcp, Dnscache, HomeGroupProvider, iphlpsvc, LanmanWorkstation,
> Netlogon, Netman, netprofm, NlaSvc, SessionEnv, SharedAccess,
> WinHttpAutoProxySvc, WwanSvc
>
> Some of above services can't be restarted and the system will need to be
> restarted in order for the registry changes to take effect.
>
> ...
>
> So, since at least one registry data changes need a system restart. It's
> best to simply give a warning to the user that the registry changes will not
> have any effect until the system is restarted.

No, I included all the changes between Before.reg and After.reg for
completeness' sake in case someone spotted something of relevance to the
screensaver setting that I wasn't aware of, but most likely the first
under [HKCU/Control Panel/Desktop] is the only one that matters, so,
rather along the lines of what I was beginning to suspect, according to
your helpful information above, I have to explore how to broadcast a
WM_SETTINGCHANGE window message after making the registry changes.

Thanks for the helpful explanation.

--

Fake news kills!

I may be contacted via the contact address given on my website:
www.macfh.co.uk

Re: Setting screensaver from command-line

<ugj7no$1cm8p$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7180&group=alt.windows7.general#7180

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Mon, 16 Oct 2023 12:44:53 +0100
Organization: A noiseless patient Spider
Lines: 226
Message-ID: <ugj7no$1cm8p$1@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 16 Oct 2023 11:44:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="070c879eabde6028cbcf0dde88c0150f";
logging-data="1464601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19z1v9J66tRumMGy7/APl/85WzsuHWfvEQ="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:6cPBlXMi+iIQ7fp/uNAMsspDdNQ=
In-Reply-To: <ugh5rq$k0fu$1@dont-email.me>
Content-Language: en-GB
 by: Java Jive - Mon, 16 Oct 2023 11:44 UTC

Further background ...

On 15/10/2023 18:00, Java Jive wrote:
>
> 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.

So this is the Win7+, possibly Vista+, version, which doesn't work as
expected:

> @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.

.... but things are much easier in XP. There, when manually you set the
Screensaver to 'None', the 'On resume, password protect' setting becomes
greyed out and disabled, and my XP equivalent BATch file works exactly
as expected. The power setting change is simpler too, because you can
specify the power scheme directly by name, instead of having to go and
find its GUID. By comparison with XP I suspect the isolated and
anomalous behaviour of the lock-screen setting since W7 (possibly Vista)
is actually a bug.

Here's the working XP version:

@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 /0 or /1 leading parameter turns the screen
saver off and on respectively
SET Switch="1"

:NextPar
IF /i "%1" EQU "/0" (
SET Switch="0"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/1" (
SET Switch="1"
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
Rem 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'
ECHO Setting Power Scheme to 'Stay Awake'
powercfg /setactive "Stay Awake"
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
Rem 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'
ECHO Setting Power Scheme to 'Presentation'
powercfg /setactive "Presentation"
GOTO Quit

:Quit
SET Switch=
SET PName=
SET GUID=

ECHO.

--

Fake news kills!

I may be contacted via the contact address given on my website:
www.macfh.co.uk

Re: Setting screensaver from command-line

<ugjj2u$1ffde$2@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7182&group=alt.windows7.general#7182

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Zaidy...@air.isp.spam (Zaidy036)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Mon, 16 Oct 2023 10:58:38 -0400
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <ugjj2u$1ffde$2@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
<ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>
Reply-To: Zaidy036@air.isp.spam
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Oct 2023 14:58:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f19bee6c2cb1a8e656e8a43c609512dd";
logging-data="1555886"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UWZ0Xdq+f8IJ34McXyf1WH6yiu2YBi7k="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:c/YSXApi9wjM6IHrJK2eLvVz810=
Content-Language: en-US
In-Reply-To: <ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net>
 by: Zaidy036 - Mon, 16 Oct 2023 14:58 UTC

On 10/16/2023 4:33 AM, JJ wrote:
> On Sun, 15 Oct 2023 18:00:38 +0100, Java Jive wrote:
>> 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]
>
> Registry data changes in `HKEY_CURRENT_USER\Control Panel` can be notified
> by broadcasting WM_SETTINGCHANGE window message, but batch file alone
> doesn't have that capability. A separate tool is neeed. e.g. AutoHotkey,
> AutoIt, PowerShell, etc.
>
>> [HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32]
>
> Notification of changes of registry data in this key is not needed, as they
> are always re-read when the dialog is needed.
>
>> [HKU\<ID>\Software\Classes\Local
>> Settings\Software\Microsoft\Windows\Shell\Bags\584\ComDlgLegacy]
>
> Explorer doesn't re-read registry data under
> `HKU\<ID>\Software\Classes\Local
> Settings\Software\Microsoft\Windows\Shell\Bags` each time a folder view is
> needed. Even if there was registry changes window message notification. Only
> system restart, user re-login, or EXPLORER.EXE process restart will re-read
> them.
>
> Same thing applies to registry data in
> `HKU\<ID>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist`
> key. PS: it's used to cache things. See: Nirsoft UserAssistView tool.
>
>> [HKLM\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a03-9b1a-11d4-9123-0050047759bc}\24]
>
> NSI service registry data changes is not notifiable. The service will need
> to be restarted for changes to take effect. However, the service is needed
> by various other network related services. i.e. at least these:
>
> Browser, Dhcp, Dnscache, HomeGroupProvider, iphlpsvc, LanmanWorkstation,
> Netlogon, Netman, netprofm, NlaSvc, SessionEnv, SharedAccess,
> WinHttpAutoProxySvc, WwanSvc
>
> Some of above services can't be restarted and the system will need to be
> restarted in order for the registry changes to take effect.
>
> ...
>
> So, since at least one registry data changes need a system restart. It's
> best to simply give a warning to the user that the registry changes will not
> have any effect until the system is restarted.
in a batch run CONTROL DESK.CPL,SCREENSAVER,@SCREENSAVER
and then use AutoIt or PTFBpro to make settings and close GUI
then no need to reboot for RegEdits to work

Re: Setting screensaver from command-line

<ugkefl$2gbni$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7183&group=alt.windows7.general#7183

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Mon, 16 Oct 2023 23:46:10 +0100
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <ugkefl$2gbni$1@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
<ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net> <ugj64v$1c8p4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Oct 2023 22:46:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dc71ede998e24eeddf44dfd887bffbf7";
logging-data="2633458"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JwiGAweQW6j8Gt20+qUpD/ZL+p624J+s="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:+2W2ZlFv5HW2RceLzFUWA0V8SPA=
Content-Language: en-GB
In-Reply-To: <ugj64v$1c8p4$1@dont-email.me>
 by: Java Jive - Mon, 16 Oct 2023 22:46 UTC

On 16/10/2023 12:17, Java Jive wrote:
>
> rather along the lines of what I was beginning to suspect, according to
> your helpful information above, I have to explore how to broadcast a
> WM_SETTINGCHANGE window message after making the registry changes.
>
> Thanks for the helpful explanation.

After a search online, I adapted the following PowerShell code snippet
and saved it as WMSettingsChange.ps1, and within the BATch file after
the label :Quit added the line ...

powershell -ExecutionPolicy ByPass -File <path>\WMSettingsChange.ps1

.... which runs without any discernible error, but the lockscreen is
still enabled after launching the screensaver properties.

I reckon this is a bug.

WMSettingsChange.ps1:
=====================

Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg,
UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr
lpdwResult);
"@

function Send-SettingChange {
$HWND_BROADCAST = [IntPtr] 0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [UIntPtr]::Zero

[void] ([Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST,
$WM_SETTINGCHANGE, [UIntPtr]::Zero, "HKEY_CURRENT_USER\Control
Panel\Desktop", 2, 5000, [ref] $result))
}

For the registry key name I tried all of (as strings in quotes, an error
was generated when I tried the last without)...

HKEY_CURRENT_USER\Control Panel\Desktop
HKEY_CURRENT_USER
Control Panel
Desktop
NULL

.... as per this documentation by Microsoft ...

https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange

.... but none made any difference, the setting remained stubbornly enabled.

--

Fake news kills!

I may be contacted via the contact address given on my website:
www.macfh.co.uk

Re: Setting screensaver from command-line

<1pt6dixyxbq5s$.8in7fm3uk8o1$.dlg@40tude.net>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7184&group=alt.windows7.general#7184

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jj4pub...@outlook.com (JJ)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Wed, 18 Oct 2023 00:31:38 +0700
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <1pt6dixyxbq5s$.8in7fm3uk8o1$.dlg@40tude.net>
References: <ugh5rq$k0fu$1@dont-email.me> <ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net> <ugj64v$1c8p4$1@dont-email.me> <ugkefl$2gbni$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="23036f2bfc6a98c14dcbbe90b3a0fdf9";
logging-data="3257536"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+z+ImbkKjv0wee+JW1nDGatsX872HOxlU="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:NqQ2k3zLJXXBBYXL9+2RsRH3aD8=
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Tue, 17 Oct 2023 17:31 UTC

On Mon, 16 Oct 2023 23:46:10 +0100, Java Jive wrote:
> On 16/10/2023 12:17, Java Jive wrote:
>>
>> rather along the lines of what I was beginning to suspect, according to
>> your helpful information above, I have to explore how to broadcast a
>> WM_SETTINGCHANGE window message after making the registry changes.
>>
>> Thanks for the helpful explanation.
>
> After a search online, I adapted the following PowerShell code snippet
> and saved it as WMSettingsChange.ps1, and within the BATch file after
> the label :Quit added the line ...
>
> powershell -ExecutionPolicy ByPass -File <path>\WMSettingsChange.ps1
>
> .... which runs without any discernible error, but the lockscreen is
> still enabled after launching the screensaver properties.
>
> I reckon this is a bug.
>
> WMSettingsChange.ps1:
> =====================
>
> Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
> [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
> public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg,
> UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr
> lpdwResult);
> "@
>
> function Send-SettingChange {
> $HWND_BROADCAST = [IntPtr] 0xffff;
> $WM_SETTINGCHANGE = 0x1a;
> $result = [UIntPtr]::Zero
>
> [void] ([Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST,
> $WM_SETTINGCHANGE, [UIntPtr]::Zero, "HKEY_CURRENT_USER\Control
> Panel\Desktop", 2, 5000, [ref] $result))
> }
>
> For the registry key name I tried all of (as strings in quotes, an error
> was generated when I tried the last without)...
>
> HKEY_CURRENT_USER\Control Panel\Desktop
> HKEY_CURRENT_USER
> Control Panel
> Desktop
> NULL
>
> .... as per this documentation by Microsoft ...
>
> https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange
>
> .... but none made any difference, the setting remained stubbornly enabled.

For screen saver related settings which are covered by the
`SystemParametersInfo` Windows API function, specify the correct action
value to WParam. Multiple settings will require separate message broadcasts
for each SystemParametersInfo action.

Re: Setting screensaver from command-line

<ugmnij$34v8o$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7185&group=alt.windows7.general#7185

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line
Date: Tue, 17 Oct 2023 20:33:36 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <ugmnij$34v8o$1@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
<ut5v9jkf18ky$.kcjut762w5lw$.dlg@40tude.net> <ugj64v$1c8p4$1@dont-email.me>
<ugkefl$2gbni$1@dont-email.me> <1pt6dixyxbq5s$.8in7fm3uk8o1$.dlg@40tude.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 17 Oct 2023 19:33:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dc71ede998e24eeddf44dfd887bffbf7";
logging-data="3308824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182PJ6TwHINk/IleH623HMIItVRfs6tJMM="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:Vc6aCOqsJfyk1JsOOUGAF7UJGZo=
Content-Language: en-GB
In-Reply-To: <1pt6dixyxbq5s$.8in7fm3uk8o1$.dlg@40tude.net>
 by: Java Jive - Tue, 17 Oct 2023 19:33 UTC

On 17/10/2023 18:31, JJ wrote:
>
> On Mon, 16 Oct 2023 23:46:10 +0100, Java Jive wrote:
>>
>> WMSettingsChange.ps1:
>> =====================
>>
>> Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
>> [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
>> public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg,
>> UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr
>> lpdwResult);
>> "@
>>
>> function Send-SettingChange {
>> $HWND_BROADCAST = [IntPtr] 0xffff;
>> $WM_SETTINGCHANGE = 0x1a;
>> $result = [UIntPtr]::Zero
>>
>> [void] ([Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST,
>> $WM_SETTINGCHANGE, [UIntPtr]::Zero, "HKEY_CURRENT_USER\Control
>> Panel\Desktop", 2, 5000, [ref] $result))
>> }
>>
>> For the registry key name I tried all of (as strings in quotes, an error
>> was generated when I tried the last without)...
>>
>> HKEY_CURRENT_USER\Control Panel\Desktop
>> HKEY_CURRENT_USER
>> Control Panel
>> Desktop
>> NULL
>>
>> .... as per this documentation by Microsoft ...
>>
>> https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange
>>
>> .... but none made any difference, the setting remained stubbornly enabled.
>
> For screen saver related settings which are covered by the
> `SystemParametersInfo` Windows API function, specify the correct action
> value to WParam. Multiple settings will require separate message broadcasts
> for each SystemParametersInfo action.

Thanks, but made no odds when I tried it. The lock-screen setting is
still not changed.

--

Fake news kills!

I may be contacted via the contact address given on my website:
www.macfh.co.uk

Re: Setting screensaver from command-line [SOLVED]

<uhav5s$nrm6$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=7197&group=alt.windows7.general#7197

  copy link   Newsgroups: alt.windows7.general
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jav...@evij.com.invalid (Java Jive)
Newsgroups: alt.windows7.general
Subject: Re: Setting screensaver from command-line [SOLVED]
Date: Wed, 25 Oct 2023 12:46:03 +0100
Organization: A noiseless patient Spider
Lines: 291
Message-ID: <uhav5s$nrm6$1@dont-email.me>
References: <ugh5rq$k0fu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 25 Oct 2023 11:46:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="600267c8360b36a1c6cad8b4e7d7b168";
logging-data="782022"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uks1C0s65HkF8n3Th6et6hAbJC+znoNA="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/68.4.2
Cancel-Lock: sha1:WFNUHehxPYTEyooX8Y2eXRUGKVY=
In-Reply-To: <ugh5rq$k0fu$1@dont-email.me>
Content-Language: en-GB
 by: Java Jive - Wed, 25 Oct 2023 11:46 UTC

On 15/10/2023 18:00, Java Jive wrote:
>

As a reminder ...

> 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]

BTW, ditto for [HKCU\Control Panel\Desktop], but an entire registry dump
doesn't show HKCU as we see it in Regedit, only as HKU\<ID>.

> "ScreenSaverIsSecure"="1"
>
> ; As expected, value changes to "0"

[Snip further detail included originally for completeness' sake on the
off chance of it being relevant, but now shown to be irrelevant]

> 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.

As discussed most helpfully by JJ, something like the above is indeed
necessary. The BATch file is almost unchanged, the single new line to
achieve the above, by calling a powershell script, is commented below,
and said powershell script is discussed and appended below it [as
always, beware unintended line wrap in both] ...

Working BATch file:
@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 /0 or /1 leading parameter turns the screen
saver off and on 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
REM Line below is only significant change from previous version
powershell -ExecutionPolicy ByPass -File
C:\Programs\Utilities\WMSettingsChange.ps1
SET Switch=
SET Debug=
SET PName=
SET GUID=

ECHO.

As far as the powershell script goes, previously I posted the following,
but no-one, including myself, noticed the embarrassingly basic bug -
it includes only a function definition, not a call to the function so
defined, and consequently does nothing. Duh! Sorry about that, my
excuse is that it's been quite a while since I last did any serious
programming.

> WMSettingsChange.ps1:
> =====================
>
> Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
> [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
> public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg,
> UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr
> lpdwResult);
> "@
>
> function Send-SettingChange {
> $HWND_BROADCAST = [IntPtr] 0xffff;
> $WM_SETTINGCHANGE = 0x1a;
> $result = [UIntPtr]::Zero
>
> [void] ([Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST,
> $WM_SETTINGCHANGE, [UIntPtr]::Zero, "HKEY_CURRENT_USER\Control
> Panel\Desktop", 2, 5000, [ref] $result))
> }
>
> For the registry key name I tried all of (as strings in quotes, an error
> was generated when I tried the last without)...
>
> HKEY_CURRENT_USER\Control Panel\Desktop
> HKEY_CURRENT_USER
> Control Panel
> Desktop
> NULL
>
> .... as per this documentation by Microsoft ...
>
> https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange
>
> .... but none made any difference, the setting remained stubbornly enabled.

As soon as I included a function call ...

Send-SettingChange;

.... all hell broke loose, but eventually I was able to remove all the
errors except one (ignore the line number, because by then other things
had changed from the above):

Cannot convert argument "6", with value:
"System.Management.Automation.PSReference", for "SendMessageTimeout" to
type "
System.UIntPtr": "Cannot convert the
"System.Management.Automation.PSReference" value of type
"System.Management.Automa
tion.PSReference" to type "System.UIntPtr"."
At C:\Programs\Utilities\WMSettingsChange.ps1:40 char:42
+ [void] ([Win32.W32N]::SendMessageTimeout <<<< ($HWND_BROADCAST,
$WM_SETTINGCHANGE, [UIntPtr]::Zero, $SPI_SCREENSA
VESECURE, 2, 5000, [System.Management.Automation.PSReference] $result));
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument


Click here to read the complete article
1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor