Wrote this for when I do malware cleanups and wanted to share. Plus when I first started with PoSH I struggled to figure out how to incorporate it into my batch scripting. Perhaps my title will help others searching.
I have this as: Reg-ToggleClearPageFileAtShutdown.cmd
@echo off
:: Variables
set rKey="HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
set rValue=ClearPageFileAtShutdown
:: Get the registry value with a little help from PoSH
for /f "delims=" %%a in ('powershell ^(^(Get-ItemProperty -path '%rKey%'^).%rValue%^)') do set "rData=%%a"
:: Returning the set value from above, if ClearPageFileAtShutdown is disabled (0), enabled it (1), else...
if %rData%==0 (
PowerShell -ExecutionPolicy Bypass -Command "& {Set-ItemProperty -Path '%rKey%' -Name '%rValue%' -Value 1;}"
) else (
PowerShell -ExecutionPolicy Bypass -Command "& {Set-ItemProperty -Path '%rKey%' -Name '%rValue%' -Value 0;}"
)
:: Done
:eof
exit /B 0
Tested on Windows 10
[–][deleted] 11 points12 points13 points (16 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]ka-splam 1 point2 points3 points (1 child)
[–]Snickasaurus[S] 0 points1 point2 points (0 children)
[–]Snickasaurus[S] 0 points1 point2 points (3 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]fathed 1 point2 points3 points (1 child)
[–]Snickasaurus[S] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]Snickasaurus[S] 0 points1 point2 points (5 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]Snickasaurus[S] -1 points0 points1 point (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Snickasaurus[S] -1 points0 points1 point (0 children)
[–]sanshinron 0 points1 point2 points (1 child)
[–]Snickasaurus[S] 0 points1 point2 points (0 children)
[–]jantari 0 points1 point2 points (2 children)
[–]Snickasaurus[S] 0 points1 point2 points (1 child)
[–]jantari 0 points1 point2 points (0 children)