First is first, thanks for pointing that with GPEDIT.MSC (manually installed on Windows Home) can be added Startup, shutdown, logon and logoff scripts.
But, how can that scripts (logon & logoff) be run with elevaled admin rigths?
I had also tried the Task Scheduler and logon works, but logoff do not work ... and i am desperated/frustated.
What i need is to run this command at Windows start:
C:\Windows\System32\reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v "ClearPageFileAtShutdown" /t REG_DWORD /d 1 /f
And what i also need is to run this other command at Windows reboot/shutdown:
C:\Windows\System32\reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v "ClearPageFileAtShutdown" /t REG_DWORD /d 0 /f
But at a point that takes effect; please note if i manually run the command (in task scheduler) to set that value to 0, if i run it just one second before click shutdown/reboot it works, no pagefile cleared (take in mind 1GiB SSD is Veracrypt full system encrypted).
Let me explain why i am so interested:
- One needed application runs at user logon (in admin rule) and if sees that registry key is not 1 (it checks it periodically every 10 or 20 seconds), locks the computer and do not allow you to use it, it runs in a mode it can not be killed (ProcessExplorer does not even kill it in admin rule).
- That application also ensures that virtual ram is configured as fixed with twice the RAM installed, if not it automatically changes it and reboots Windows.
- I do not want (neither need) 512GiB of virtual ram to be filled with zeroes at shutdown/reboot every time, think of a 1GiB SSD with Windows on a VeraCrypt cyphered system partition, that will kill my 1GiB SSD live very fast, since SSD does not recieve zeroes (recives such zeroes encrypted, so they are no zeroes anymone), that is writting half of the SSD on every reboot/shutdown.
In short words:
- I need to enable ClearPageFileAtShutdown at Windows startup, but disable it as soon as shutdown/reboot starts; to avoid SSD live shortened very fast.
Note: The computer has 256GiB of pysical RAM, i can not put 512GiB becuase of such application, it is so weird that requieres a 1GiB max size system drive or refuses to let you use Windows (sure you noted, i hate that app but i am forced to use it and they do not pay me for SSD every week or so), it also forces a reboot every 45 minutes, so makeing counts, 0.5GiB every 45' = 16 TiB per day (480 TiB per month) only just because clearing the pagefile... i hate it... not to mention time to shutdown/reboot increase a lot (if every reboot/shutdown is done at max time that app allows, aka 45', of every hour a total of 16' is dedicated to clearing pagefile, at 24h that is >6h on that clearing pagefile per day if you use it 45' every time; 550MiB/s speed), now i think you can understand my interest of avoid such clearing (mostly the SSD live but also time).
EDIT1: I had seen that Task Scheduler command is run (at shutdown/reboot) and registry key is set to 0, but at that shutdown/reboot it takes no effect, the change is done too late; so it must be a question to find an event that triggers sooner, since (User32 1074 and/or WinLogon 7002) does not trigger soon enough, user logout neither, computer lock neither; all of them are triggered too late.
EDIT2: Neither it worked soon enough with personal filter like
SCHTASKS /Create /SC ONEVENT /mo "Event[System[(EventID=1074)]]" /EC Security /tn on_shutdown_normal /tr "c:\some.bat"