@echo off
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Tuneup.bat  2020/08/13 updated 01/30/2021
:: Written by Ztruker - tenForums.com/members/ztruker.html based on forum
:: posts by Zbook - tenforums.com/members/zbook.html
:: Automatically elevates to Administrator level if needed via code from
:: Matthew Wai - tenForums.com/members/matthew-wai.html    08/14/2020
::
:: The first 4 command will take quite a while to run.
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Increase horizontal and vertical buffer sizes to hold all output from batch file
:: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mode con: cols=120 lines=1000
::
:: Restart as Admin if not already running as Admin
::
(Net session >nul 2>&1)||(PowerShell start """%~fn0""" -verb RunAs & Exit /B)

echo off
echo ###########################################################
echo # The following commands will be run in sequence.         #
echo # The first 5 will take quite a while to run, be patient. #
echo ###########################################################
echo. >&2
echo sfc /scannow
echo dism /online /cleanup-image /scanhealth
echo dism /online /cleanup-image /restorehealth
echo sfc /scannow
echo. >&2
echo chkdsk /scan
echo. >&2
echo wmic recoveros get autoreboot
echo wmic recoveros set autoreboot = false
echo wmic recoveros get autoreboot
echo wmic recoveros get DebugInfoType
echo wmic recoveros set DebugInfoType = 7
echo wmic recoveros get DebugInfoType
echo. >&2
echo wmic pagefile list /format:list
echo wmic Computersystem where name="%computername%" get AutomaticManagedPagefile
echo wmic Computersystem where name="%computername%" set AutomaticManagedPagefile=True
echo wmic Computersystem where name="%computername%" get AutomaticManagedPagefile
echo. >&2
echo bcdedit /enum {badmemory}
echo. >&2
@echo on

sfc /scannow
dism /online /cleanup-image /scanhealth
dism /online /cleanup-image /restorehealth
sfc /scannow

chkdsk /scan

wmic recoveros get autoreboot
wmic recoveros set autoreboot = false
wmic recoveros get autoreboot

wmic recoveros get DebugInfoType
wmic recoveros set DebugInfoType = 7
wmic recoveros get DebugInfoType

wmic pagefile list /format:list

wmic Computersystem where name="%computername%" get AutomaticManagedPagefile
wmic Computersystem where name="%computername%" set AutomaticManagedPagefile=True
wmic Computersystem where name="%computername%" get AutomaticManagedPagefile

bcdedit /enum {badmemory}

Echo off
Echo    ###################################################################################
Echo    #    How to capture batch file data and post in your thread in the BSOD forum     #
Echo    #                                                                                 #
Echo    #      Batch files and instructions for use in BSOD debugging[Part Two-Four]      #
Echo    #                                                                                 #
Echo    #        Press [V] to visit the above web page for detailed instructions.         #
Echo    #        Press [C] to close this window.                                          #
Echo    ###################################################################################
Echo.
Echo.
CHOICE /C "VC" /M "Your choice?:" >nul 2>&1
If %errorlevel%==1 (Start "" "https://www.tenforums.com/bsod-crashes-debugging/162488-batch-files-use-bsod-debugging.html#Part2" & pause) 
exit
