Skip to content

Commit

Permalink
Update tron.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
vocatus authored Mar 6, 2018
1 parent 34f1d8d commit 16e5dfe
Showing 1 changed file with 8 additions and 103 deletions.
111 changes: 8 additions & 103 deletions tron.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
:: Program: "That's Tron. He fights for the User."
:: Requirements: Run from the current users desktop. Run as Administrator.
:: Author: vocatus on reddit.com/r/TronScript ( vocatus.gate at gmail ) // PGP key: 0x07d1490f82a211a2
:: Version: 1.1.1 + Add uploading of Metro app list dump if -udl switch is used
:: Version: 1.1.1 + Add upload of Metro app list dump if -udl switch is used
:: / Move Stage 7 code out of tron.bat into it's own discrete script
:: 1.1.0 / Move network connection detection code into initialize_environment.bat
:: + Add display of whether or not warnings and errors were detected to end-screen
:: 1.0.9 + Add support for detection of Internet connection on French language systems. Thanks to u/mr_marmotte
Expand Down Expand Up @@ -47,7 +48,7 @@ SETLOCAL
:::::::::::::::::::::
color 0f
set SCRIPT_VERSION=1.1.1
set SCRIPT_DATE=2018-02-16
set SCRIPT_DATE=2018-03-06

:: Get in the correct drive (~d0) and path (~dp0). Sometimes needed when run from a network or thumb drive.
:: We stay in the \resources directory for the rest of the script
Expand Down Expand Up @@ -545,104 +546,8 @@ call stage_6_optimize\stage_6_optimize.bat
:stage_7_wrap-up
:: Stamp current stage so we can resume if we get interrupted by a reboot
echo stage_7_wrap-up>tron_stage.txt
call functions\log_with_date.bat " stage_7_wrap-up begin..."


:: JOB: Reset power settings to Windows defaults
title Tron v%TRON_VERSION% [stage_7_wrap-up] [Reset power settings]
if %PRESERVE_POWER_SCHEME%==yes (
call functions\log_with_date.bat "! PRESERVE_POWER_SCHEME (-p) set to "%PRESERVE_POWER_SCHEME%", skipping power settings reset."
) else (
call functions\log_with_date.bat " Resetting Windows power settings to defaults and re-enabling screensaver..."
if %DRY_RUN%==no (
REM Check for Windows XP/2k3
if %WIN_VER_NUM% lss 6.0 %WINDIR%\system32\powercfg.exe /RestoreDefaultPolicies >NUL 2>&1
REM Run commands for all other versions of Windows
%WINDIR%\system32\powercfg.exe -restoredefaultschemes >NUL 2>&1
)
call functions\log_with_date.bat " Done."
)


:: JOB: Get post-Tron system state (installed programs, complete file list) and generate the summary logs
title Tron v%TRON_VERSION% [stage_7_wrap-up] [Generate Summary Logs]
call functions\log_with_date.bat " Calculating post-run results for summary logs..."
if /i %DRY_RUN%==no (
:: Get list of installed programs
stage_0_prep\log_tools\siv\siv32x.exe -save=[software]="%RAW_LOGS%\installed-programs-after.txt"
:: Get list of all files
stage_0_prep\log_tools\everything\everything.exe -create-filelist %RAW_LOGS%\filelist-after.txt %SystemDrive%
:: Parse everything
REM Step 1: Find FILES that were deleted (second line is to strip everything trailing the first comma from the output)
stage_0_prep\log_tools\comm\comm.exe -23 %RAW_LOGS%\filelist-before.txt %RAW_LOGS%\filelist-after.txt | %FIND% /i /v "$RECYCLE" | %FIND% /i /v "AppData\" | %FIND% /i /v "ntuser.dat" > "%TEMP%\temp.txt"
for /f "tokens=1 delims=," %%a in ("%TEMP%\temp.txt") do echo %%a >> %SUMMARY_LOGS%\tron_removed_files.txt

REM Step 2: Find PROGRAMS that were removed. This is super ugly and complicated, but lets us avoid bundling another external utility
REM Compact the files by removing blank lines, stripping top 4 lines off file, then last two lines, then output to the final text file for comparison
copy /y %RAW_LOGS%\installed-programs-before.txt %RAW_LOGS%\before.txt >NUL
for /f "delims=" %%a in (%RAW_LOGS%\before.txt) do echo %%a>> %RAW_LOGS%\before1.txt
more +3 %RAW_LOGS%\before1.txt >> %RAW_LOGS%\before2.txt
%FINDSTR% /v /i "[==" %RAW_LOGS%\before2.txt > %RAW_LOGS%\installed-programs-before.txt

REM AFTER: Compact the files by removing blank lines, stripping top 4 lines off file, then last two lines, then output to the final text file for comparison
copy /y %RAW_LOGS%\installed-programs-after.txt %RAW_LOGS%\after.txt >NUL
for /f "delims=" %%a in (%RAW_LOGS%\after.txt) do echo %%a>> %RAW_LOGS%\after1.txt
more +3 %RAW_LOGS%\after1.txt >> %RAW_LOGS%\after2.txt
%FINDSTR% /v /i "[==" %RAW_LOGS%\after2.txt > %RAW_LOGS%\installed-programs-after.txt

REM Calculate differences, using GnuWin32 coreutil's comm.exe
stage_0_prep\log_tools\comm\comm.exe -23 %RAW_LOGS%\installed-programs-before.txt %RAW_LOGS%\installed-programs-after.txt > %SUMMARY_LOGS%\tron_removed_programs.txt

REM If the parsed file is the same as the original, we can assume nothing was removed, so just echo that into the file
fc /b %RAW_LOGS%\installed-programs-before.txt %RAW_LOGS%\installed-programs-after.txt >NUL
if %ERRORLEVEL%==0 echo No programs were removed.> %SUMMARY_LOGS%\tron_removed_programs.txt

REM Cleanup
del /f /q "%TEMP%\temp.txt" 2>NUL
del /f /q %RAW_LOGS%\before*txt 2>NUL
del /f /q %RAW_LOGS%\after*txt 2>NUL
)
call functions\log_with_date.bat " Done. Summary logs are at "%SUMMARY_LOGS%\""


:: JOB: Collect misc logs and deposit them in the log folder
title Tron v%TRON_VERSION% [stage_7_wrap-up] [Collect logs]
call functions\log_with_date.bat " Saving misc logs to "%RAW_LOGS%\"..."
if /i %DRY_RUN%==no (
if exist "%ProgramData%\Sophos\Sophos Virus Removal Tool\Logs" copy /Y "%ProgramData%\Sophos\Sophos Virus Removal Tool\Logs\*.l*" "%RAW_LOGS%" >NUL
if exist "%ProgramData%\Malwarebytes\Malwarebytes Anti-Malware\Logs" copy /Y "%ProgramData%\Malwarebytes\Malwarebytes Anti-Malware\Logs\*.xml" "%RAW_LOGS%" >NUL
if exist "%LOGPATH%\mbam-log*" move /y "%LOGPATH%\mbam-log*" "%RAW_LOGS%\"
if exist "%LOGPATH%\Sophos*" move /y "%LOGPATH%\Sophos*" "%RAW_LOGS%\"
if exist "%LOGPATH%\protection-log*" move /y "%LOGPATH%\protection-log*" "%RAW_LOGS%\"
if exist "%LOGPATH%\jre*" move /y "%LOGPATH%\jre*" "%RAW_LOGS%\"
)
call functions\log_with_date.bat " Done."


:: JOB: Create post-run Restore Point
title Tron v%TRON_VERSION% [stage_7_wrap-up] [Create Restore Point]
if %WIN_VER_NUM% geq 6.0 (
REM Remove the stupid restore point creation 24 hour cooldown timer Microsoft brilliantly introduced in Windows 8 and up
if %WIN_VER_NUM% geq 6.2 reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore" /t reg_dword /v SystemRestorePointCreationFrequency /d 0 /f >nul 2>&1
REM Create the restore point
echo "%WIN_VER%" | %FINDSTR% /i /c:"server" >NUL || (
call functions\log_with_date.bat " Creating post-run Restore Point..."
if /i %DRY_RUN%==no powershell "Checkpoint-Computer -Description 'TRON v%TRON_VERSION%: Post-run checkpoint' | Out-Null" >> "%LOGPATH%\%LOGFILE%" 2>&1
)
)
call functions\log_with_date.bat " OK."


:: JOB: Calculate saved disk space
title Tron v%TRON_VERSION% [stage_7_wrap-up] [Calculate saved disk space]
for /F "tokens=2 delims=:" %%a in ('fsutil volume diskfree %SystemDrive% ^| %FIND% /i "avail free"') do set bytes=%%a
:: GB version
::set /A FREE_SPACE_BEFORE=%bytes:~0,-3%/1024*1000/1024/1024
:: MB version
set /A FREE_SPACE_AFTER=%bytes:~0,-3%/1024*1000/1024
set /a FREE_SPACE_SAVED=%FREE_SPACE_AFTER% - %FREE_SPACE_BEFORE%

call functions\log_with_date.bat " stage_7_wrap-up complete."
title Tron v%TRON_VERSION% [stage_7_wrap-up]
call stage_7_wrap-up\stage_7_wrap-up.bat



Expand Down Expand Up @@ -746,12 +651,12 @@ call functions\log.bat " Executed as %USERDOMAIN%\%USER
call functions\log.bat " Command-line switches: %*"
call functions\log.bat " Time zone: %TIME_ZONE_NAME%"
call functions\log.bat " Safe Mode: %SAFE_MODE% %SAFEBOOT_OPTION%"
call functions\log.bat " Free space before Tron run: %FREE_SPACE_BEFORE% MB"
call functions\log.bat " Free space after Tron run: %FREE_SPACE_AFTER% MB"
call functions\log.bat " Disk space reclaimed: %FREE_SPACE_SAVED% MB *"
call functions\log.bat " Logfile: %LOGPATH%\%LOGFILE%"
call functions\log.bat " Warnings detected?: %WARNINGS_DETECTED%"
call functions\log.bat " Debug logs uploaded?: %UPLOAD_DEBUG_LOGS%"
call functions\log.bat " Free space before Tron run: %FREE_SPACE_BEFORE% MB"
call functions\log.bat " Free space after Tron run: %FREE_SPACE_AFTER% MB"
call functions\log.bat " Disk space reclaimed: %FREE_SPACE_SAVED% MB *"
call functions\log.bat ""
call functions\log.bat " * If you see negative disk space don't panic. Due to how some of Tron's"
call functions\log.bat " functions work, actual space reclaimed will not be visible until after"
Expand Down

0 comments on commit 16e5dfe

Please sign in to comment.