Guest User

tron with skip mbam

a guest
Dec 23rd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 65.73 KB | None | 0 0
  1. :: Purpose:       Runs a series of cleaners and anti-virus engines to clean up/disinfect a PC
  2. ::                  Kevin Flynn:  "Who's that guy?"
  3. ::                  Program:      "That's Tron. He fights for the User."
  4. :: Requirements:  1. Administrator access
  5. ::                2. Safe mode is strongly recommended (though not required)
  6. :: Author:        vocatus on reddit.com/r/sysadmin ( [email protected] ) // PGP key ID: 0x82A211A2
  7. :: Version:       4.3.2 ! bugfix:                Fix crash condition where script would terminate if run by a user with spaces in the name. Thanks to /u/evileyerex
  8. ::                      * improvement:ssd_check: Check for additional string commonly seen on SSDs: "SandForce". Thanks to /u/Techie4Life83
  9. ::                      
  10. ::
  11. :: Usage:         Run this script in Safe Mode as an Administrator and reboot when finished. That's it.
  12. ::
  13. ::                OPTIONAL command-line flags (can be combined, none are required):
  14. ::                      -a  Automatic mode (no welcome screen or prompts; implies -e)
  15. ::                      -c  Config dump (display config. Can be used with other flags to see what
  16. ::                          WOULD happen, but script will never execute if this flag is used)
  17. ::                      -d  Dry run (run through script without executing any jobs)
  18. ::                      -e  Accept EULA (suppress display of disclaimer warning screen)
  19. ::                      -er Email a report when finished. Requires you to configure SwithMailSettings.xml
  20. ::                      -h  Display help text
  21. ::                      -m  Preserve default Metro apps (don't remove them)
  22. ::                      -o  Power off after running (overrides -r)
  23. ::                      -p  Preserve power settings (don't reset power settings to default)
  24. ::                      -r  Reboot (auto-reboot 30 seconds after completion)
  25. ::                      -sa Skip anti-virus scans (Sophos, Vipre, MBAM)
  26. ::                      -smbam Skip only Malwarebytes
  27. ::                      -sb Skip de-bloat (OEM bloatware removal; implies -m)
  28. ::                      -sd Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
  29. ::                      -sp Skip patches (do not patch 7-Zip, Java Runtime, Adobe Flash and Reader)
  30. ::                      -v  Verbose. Show as much output as possible. NOTE: Significantly slower!
  31. ::                      -x  Self-destruct. Tron deletes itself after running and leaves logs intact
  32. ::
  33. ::                If you don't like the defaults and don't want to use the command-line, edit the variables below to change the script defaults.
  34.  
  35. ::                U.S. Army Warrant Officer Corps - Quiet Professionals
  36. SETLOCAL
  37. @echo off
  38.  
  39.  
  40.  
  41.  
  42. :::::::::::::::
  43. :: VARIABLES :: ---------------- These are the defaults. Change them if you want ------------------- ::
  44. :::::::::::::::
  45. :: Rules for variables:
  46. ::  * NO quotes!                    (bad:  "c:\directory\path"       )
  47. ::  * NO trailing slashes on paths! (bad:   c:\directory\            )
  48. ::  * Spaces are okay               (okay:  c:\my folder\with spaces )
  49. ::  * Network paths are okay        (okay:  \\server\share name      )
  50.  
  51. :: Log settings and quarantined files path (note: quarantined files path is currently unused by Tron)
  52. set LOGPATH=%SystemDrive%\Logs
  53. set LOGFILE=tron.log
  54. set QUARANTINE_PATH=%LOGPATH%\tron_quarantined_files
  55.  
  56. :: ! All variables here are overridden if their respective command-line flag is used
  57. :: AUTORUN               (-a)  = Automatic execution (no welcome screen or prompts), implies -e.
  58. :: DRY_RUN               (-d)  = Run through script but skip all actual actions (test mode)
  59. :: EULA_ACCEPTED         (-e)  = Accept EULA (suppress display of disclaimer warning screen)
  60. :: EMAIL_REPORT          (-er) = Email post-run report with log file. Requires you to have configured SwithMailSettings.xml prior to running
  61. :: PRESERVE_METRO_APPS   (-m)  = Don't remove stock Metro apps
  62. :: AUTO_SHUTDOWN         (-o)  = Shutdown after the finishing. Overrides auto-reboot
  63. :: PRESERVE_POWER_SCHEME (-p)  = Preserve active power scheme. Default is to reset power scheme to Windows defaults at the end of Tron
  64. :: AUTO_REBOOT_DELAY     (-r)  = Post-run delay (in seconds) before rebooting. Set to 0 to disable auto-reboot
  65. :: SKIP_ANTIVIRUS_SCANS  (-sa) = Set to yes to skip anti-virus scanners (Sophos, Vipre, MBAM)
  66. :: SKIP_MBAM_ONLY    (-smbam) = Set to yes to skip malwarebytes
  67. :: SKIP_DEBLOAT          (-sb) = Set to yes to skip de-bloat section (OEM bloat removal). Implies -m
  68. :: SKIP_DEFRAG           (-sd) = Set to yes to skip defrag regardless whether the system drive is an SSD or not. When set to "no" the script will auto-detect SSDs
  69.  
  70. and skip defrag if one is detected
  71. :: SKIP_PATCHES          (-sp) = Set to yes to skip patches (do not patch 7-Zip, Java Runtime, Adobe Flash Player and Adobe Reader)
  72. :: VERBOSE               (-v)  = When possible, show as much output as possible from each program Tron calls (e.g. Sophos, Vipre, etc). NOTE: This is often much
  73.  
  74. slower
  75. :: SELF_DESTRUCT         (-x)  = Set to yes to have Tron automatically delete itself after running. Leaves logs intact
  76. set AUTORUN=no
  77. set DRY_RUN=no
  78. set EULA_ACCEPTED=no
  79. set EMAIL_REPORT=no
  80. set PRESERVE_METRO_APPS=no
  81. set AUTO_SHUTDOWN=no
  82. set PRESERVE_POWER_SCHEME=no
  83. set AUTO_REBOOT_DELAY=0
  84. set SKIP_ANTIVIRUS_SCANS=no
  85. set SKIP_MBAM_ONLY=no
  86. set SKIP_DEBLOAT=no
  87. set SKIP_DEFRAG=no
  88. set SKIP_PATCHES=no
  89. set VERBOSE=no
  90. set SELF_DESTRUCT=no
  91.  
  92.  
  93.  
  94.  
  95.  
  96. :: ------------------------------------------------------------------------------------------------- ::
  97. :: ---------------- Don't edit anything below this line lest you awaken the Balrog ----------------- ::
  98. :: ------------------------------------------------------------------------------------------------- ::
  99.  
  100.  
  101.  
  102.  
  103.  
  104. :::::::::::::::::::::
  105. :: PREP AND CHECKS ::
  106. :::::::::::::::::::::
  107. cls
  108. color 0f
  109. set SCRIPT_VERSION=4.3.2
  110. set SCRIPT_DATE=2014-12-23
  111. title TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%)
  112.  
  113. :: Get the date into ISO 8601 standard date format (yyyy-mm-dd) so we can use it
  114. FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
  115. set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
  116.  
  117. :: Initialize script-internal variables. Most of these get clobbered later so don't change them here
  118. set CONFIG_DUMP=no
  119. set REPO_URL=http://bmrf.org/repos/tron
  120. set REPO_BTSYNC_KEY=BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47
  121. set REPO_SCRIPT_DATE=0
  122. set REPO_SCRIPT_VERSION=0
  123. set HELP=no
  124. set TARGET_METRO=no
  125. set FREE_SPACE_AFTER=0
  126. set FREE_SPACE_BEFORE=0
  127. set FREE_SPACE_SAVED=0
  128. set UNICORN_POWER_MODE=off
  129.  
  130.  
  131. :: Get in the correct drive (~d0). This is sometimes needed when running from a thumb drive
  132. %~d0 2>NUL
  133. :: Get in the correct path (~dp0). This is useful if we start from a network share, it converts CWD to a drive letter
  134. pushd %~dp0 2>NUL
  135.  
  136.  
  137. :: PREP JOB: Parse command-line arguments
  138. for %%i in (%*) do (
  139.     if /i %%i==-a set AUTORUN=yes
  140.     if /i %%i==-c set CONFIG_DUMP=yes
  141.     if /i %%i==-d set DRY_RUN=yes
  142.     if /i %%i==-e set EULA_ACCEPTED=yes
  143.     if /i %%i==-er set EMAIL_REPORT=yes
  144.     if /i %%i==-h set HELP=yes
  145.     if /i %%i==-m set PRESERVE_METRO_APPS=yes
  146.     if /i %%i==-o set AUTO_SHUTDOWN=yes
  147.     if /i %%i==-p set PRESERVE_POWER_SCHEME=yes
  148.     if /i %%i==-r set AUTO_REBOOT_DELAY=30
  149.     if /i %%i==-sa set SKIP_ANTIVIRUS_SCANS=yes
  150.     if /i %%i==-smbam set SKIP_MBAM_ONLY=yes
  151.     if /i %%i==-sb set SKIP_DEBLOAT=yes
  152.     if /i %%i==-sd set SKIP_DEFRAG=yes
  153.     if /i %%i==-sp set SKIP_PATCHES=yes
  154.     if /i %%i==-v set VERBOSE=yes
  155.     if /i %%i==-x set SELF_DESTRUCT=yes
  156.     if %%i==-UPM set UNICORN_POWER_MODE=on
  157.     )
  158.  
  159.  
  160. :: PREP JOB: Execute help if requested
  161. if /i %HELP%==yes (
  162.     ::cls
  163.     echo.
  164.     echo  Tron v%SCRIPT_VERSION% ^(%SCRIPT_DATE%^)
  165.     echo  Author: vocatus on reddit.com/r/sysadmin
  166.     echo.
  167.     echo   Usage: %0%.bat ^[-a -c -d -e -er -m -o -p -r -sa -sb -sd -sp -v -x^] ^| ^[-h^]
  168.     echo.
  169.     echo   Optional flags ^(can be combined^):
  170.     echo    -a  Automatic mode ^(no welcome screen or prompts; implies -e^)
  171.     echo    -c  Config dump ^(display config. Can be used with other flags to see what
  172.     echo        WOULD happen, but script will never execute if this flag is used^)
  173.     echo    -d  Dry run ^(run through script but don't execute any jobs^)
  174.     echo    -e  Accept EULA ^(suppress display of disclaimer warning screen^)
  175.     echo    -er Email a report when finished. Requires you to configure SwithMailSettings.xml
  176.     echo    -m  Preserve default Metro apps ^(don't remove them^)
  177.     echo    -o  Power off after running ^(overrides -r^)
  178.     echo    -p  Preserve power settings ^(don't reset power settings to default^)
  179.     echo    -r  Reboot automatically ^(auto-reboot 30 seconds after completion^)
  180.     echo    -sa Skip anti-virus scans ^(Sophos, Vipre, MBAM^)
  181.     echo    -smbam Skip malwarebytes only
  182.     echo    -sb Skip de-bloat ^(OEM bloatware removal; implies -m^)
  183.     echo    -sd Skip defrag ^(force Tron to ALWAYS skip Stage 5 defrag^)
  184.     echo    -sp Skip patches ^(do not patch 7-Zip, Java Runtime, Adobe Flash or Reader^)
  185.     echo    -v  Verbose. Show as much output as possible. NOTE: Significantly slower!
  186.     echo    -x  Self-destruct. Tron deletes itself after running and leaves logs intact
  187.     echo.
  188.     echo   Misc flags ^(must be used alone^)
  189.     echo    -h  Display this help text
  190.     echo.
  191.     exit /b 0
  192.     )
  193.  
  194.  
  195. :: PREP JOB: Force WMIC location in case the system PATH is messed up
  196. set WMIC=%SystemRoot%\system32\wbem\wmic.exe
  197.  
  198.  
  199. :: PREP JOB: Detect the version of Windows we're on. This determines a few things later in the script, such as which versions of SFC and powercfg.exe we run, as well
  200.  
  201. as whether or not to attempt removal of Windows 8/8.1 metro apps
  202. set WIN_VER=undetected
  203. for /f "tokens=3*" %%i IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| Find "ProductName"') DO set WIN_VER=%%i %%j
  204.  
  205.  
  206. :: PREP JOB: Detect Solid State hard drives (determines if post-run defrag executes or not)
  207. :: Basically we use a trick to set the global SSD_DETECTED variable outside of the setlocal block by stacking it on the same line so it gets executed along with
  208.  
  209. ENDLOCAL
  210. :: Big time thanks to reddit.com/user/Suddenly_Engineer and reddit.com/user/Aberu for helping with this
  211. pushd resources\stage_5_optimize\defrag
  212. set SSD_DETECTED=no
  213. setlocal enabledelayedexpansion
  214. for /f "tokens=1" %%i in ('smartctl --scan') do (
  215.     smartctl %%i -a | find /i "Solid State" >NUL
  216.     if "!ERRORLEVEL!"=="0" endlocal disabledelayedexpansion && set SSD_DETECTED=yes&& goto detect_safe_mode
  217.     )
  218. for /f "tokens=1" %%i in ('smartctl --scan') do (
  219.     smartctl %%i -a | find /i "SSD" >NUL
  220.     if "!ERRORLEVEL!"=="0" endlocal disabledelayedexpansion && set SSD_DETECTED=yes&& goto detect_safe_mode
  221.     )
  222. for /f "tokens=1" %%i in ('smartctl --scan') do (
  223.     smartctl %%i -a | find /i "RAID" >NUL
  224.     if "!ERRORLEVEL!"=="0" endlocal disabledelayedexpansion && set SSD_DETECTED=yes&& goto detect_safe_mode
  225.     )
  226. for /f "tokens=1" %%i in ('smartctl --scan') do (
  227.     smartctl %%i -a | find /i "SandForce" >NUL
  228.     if "!ERRORLEVEL!"=="0" endlocal disabledelayedexpansion && set SSD_DETECTED=yes&& goto detect_safe_mode
  229.     )
  230. endlocal disabledelayedexpansion
  231.  
  232.  
  233. :: PREP JOB: Detect if the system is in Safe Mode
  234. :detect_safe_mode
  235. popd
  236. set SAFE_MODE=no
  237. if /i "%SAFEBOOT_OPTION%"=="MINIMAL" set SAFE_MODE=yes
  238. if /i "%SAFEBOOT_OPTION%"=="NETWORK" set SAFE_MODE=yes
  239.  
  240.  
  241. :: PREP JOB: Get free space on the system drive and stash it for comparison later
  242. :: Thanks to Stack Overflow user Aacini in this post: http://stackoverflow.com/a/20392479/1347428
  243. for /F "tokens=2 delims=:" %%a in ('fsutil volume diskfree %SystemDrive% ^| find /i "avail free"') do set bytes=%%a
  244. :: GB version
  245. ::set /A FREE_SPACE_BEFORE=%bytes:~0,-3%/1024*1000/1024/1024
  246. :: MB version
  247. set /A FREE_SPACE_BEFORE=%bytes:~0,-3%/1024*1000/1024
  248.  
  249.  
  250. :: PREP JOB: Re-enable the standard "F8" key functionality for choosing bootup options (Microsoft disables it by default starting in Windows 8 and up)
  251. :: Read WIN_VER and run the scan if we're on some derivative of 8. We don't need to check for Server 2012 because it's set to "legacy" by default.
  252. if "%WIN_VER:~0,9%"=="Windows 8" (
  253.     bcdedit /set {default} bootmenupolicy legacy
  254.     )
  255.  
  256.  
  257. :: PREP JOB: Update check
  258. pushd resources\stage_0_prep\check_update
  259. :: Skip this job if we're doing a dry run or if AUTORUN is set
  260. if /i %DRY_RUN%==yes goto skip_update_check
  261. if /i %AUTORUN%==yes goto skip_update_check
  262.  
  263. :: We use wget to fetch md5sums.txt from the repo and parse through it, extracting the latest version number and release date from last line of the file (which is
  264.  
  265. always the latest release)
  266. :: Get the file from the repo
  267. wget %REPO_URL%/md5sums.txt -O %TEMP%\md5sums.txt 2>NUL
  268. :: Assuming there was no error, go ahead and extract version number into REPO_SCRIPT_VERSION, and release date into REPO_SCRIPT_DATE
  269. if /i %ERRORLEVEL%==0 (
  270.     for /f "tokens=1,2,3 delims= " %%a in (%TEMP%\md5sums.txt) do set WORKING=%%c
  271.     for /f "tokens=1,2,3,4 delims= " %%a in (%TEMP%\md5sums.txt) do set WORKING2=%%d
  272.     )
  273. if /i %ERRORLEVEL%==0 (
  274.     set REPO_SCRIPT_VERSION=%WORKING:~1,6%
  275.     set REPO_SCRIPT_DATE=%WORKING2:~1,10%
  276.     )
  277.  
  278. :: clean up and reset the window title since wget clobbers it
  279. if exist %TEMP%\md5sum* del %TEMP%\md5sum*
  280. title TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%)
  281.  
  282. :: Notify if an update was found
  283. if /i %SCRIPT_VERSION% LSS %REPO_SCRIPT_VERSION% (
  284.     color 8a
  285.     cls
  286.     echo.
  287.     echo  ! A newer version of Tron is available on the official repo.
  288.     echo.
  289.     echo    Your version:   %SCRIPT_VERSION% ^(%SCRIPT_DATE%^)
  290.     echo    Latest version: %REPO_SCRIPT_VERSION% ^(%REPO_SCRIPT_DATE%^)
  291.     echo.
  292.     echo    Strongly recommend grabbing latest version before continuing.
  293.     echo.
  294.     echo    Option 1: Sync directly from repo using BT Sync read-only key:
  295.     echo     %REPO_BTSYNC_KEY%
  296.     echo.
  297.     echo    Option 2: Download the latest self-extracting .exe:
  298.     echo     %REPO_URL%
  299.     echo.
  300.     pause
  301.     color 0f
  302.     )
  303.    
  304. :skip_update_check
  305. popd
  306.  
  307.  
  308. :: PREP JOB: Execute config dump if requested
  309. if /i %CONFIG_DUMP%==yes (
  310.     cls
  311.     echo.
  312.     echo   Tron v%SCRIPT_VERSION% ^(%SCRIPT_DATE%^) config dump
  313.     echo.
  314.     echo   Command-line arguments:
  315.     echo    %*
  316.     echo.
  317.     echo   Variables ^(user-set^):
  318.     echo    AUTORUN:                %AUTORUN%
  319.     echo    AUTO_REBOOT_DELAY:      %AUTO_REBOOT_DELAY%
  320.     echo    CONFIG_DUMP:            %CONFIG_DUMP%
  321.     echo    AUTO_SHUTDOWN:          %AUTO_SHUTDOWN%
  322.     echo    DRY_RUN:                %DRY_RUN%
  323.     echo    EMAIL_REPORT:           %EMAIL_REPORT%
  324.     echo    EULA_ACCEPTED:          %EULA_ACCEPTED%
  325.     echo    LOGPATH:                %LOGPATH%
  326.     echo    LOGFILE:                %LOGFILE%
  327.     echo    PRESERVE_METRO_APPS:    %PRESERVE_METRO_APPS%
  328.     echo    PRESERVE_POWER_SCHEME:  %PRESERVE_POWER_SCHEME%
  329.     echo    QUARANTINE_PATH:        %QUARANTINE_PATH%
  330.     echo    SELF_DESTRUCT:          %SELF_DESTRUCT%
  331.     echo    SKIP_ANTIVIRUS_SCANS    %SKIP_ANTIVIRUS_SCANS%
  332.     echo    SKIP_MBAM_ONLY      %SKIP_MBAM_ONLY%
  333.     echo    SKIP_DEBLOAT        %SKIP_DEBLOAT%
  334.     echo    SKIP_DEFRAG:            %SKIP_DEFRAG%
  335.     echo    SKIP_PATCHES:           %SKIP_PATCHES%
  336.     echo    UNICORN_POWER_MODE:     %UNICORN_POWER_MODE%
  337.     echo    VERBOSE:                %VERBOSE%
  338.     echo.
  339.     echo   Variables ^(script-internal^):
  340.     echo    CUR_DATE:               %CUR_DATE%
  341.     echo    DTS:                    %DTS%
  342.     echo    FREE_SPACE_AFTER:       %FREE_SPACE_AFTER%
  343.     echo    FREE_SPACE_BEFORE:      %FREE_SPACE_BEFORE%
  344.     echo    FREE_SPACE_SAVED:       %FREE_SPACE_SAVED%
  345.     echo    HELP:                   %HELP%
  346.     echo    SAFE_MODE:              %SAFE_MODE%
  347.     echo    SAFEBOOT_OPTION:        %SAFEBOOT_OPTION%
  348.     echo    SSD_DETECTED:           %SSD_DETECTED%
  349.     echo    TEMP:                   %TEMP%
  350.     echo    TIME:                   %TIME%
  351.     echo    PROCESSOR_ARCHITECTURE: %PROCESSOR_ARCHITECTURE%
  352.     echo    REPO_BTSYNC_KEY:        %REPO_BTSYNC_KEY%
  353.     echo    REPO_URL:               %REPO_URL%
  354.     echo    REPO_SCRIPT_VERSION:    %REPO_SCRIPT_VERSION%
  355.     echo    REPO_SCRIPT_DATE:       %REPO_SCRIPT_DATE%
  356.     echo    SCRIPT_VERSION:         %SCRIPT_VERSION%
  357.     echo    SCRIPT_DATE:            %SCRIPT_DATE%
  358.     :: We need this setlocal/endlocal pair because on Vista the OS name has "(TM)" in it, which breaks the script. Sigh
  359.     setlocal enabledelayedexpansion
  360.     echo    WIN_VER:                !WIN_VER!
  361.     endlocal disabledelayedexpansion
  362.     echo    WMIC:                   %WMIC%
  363.     echo.
  364.     exit /b 0
  365.     )
  366.  
  367.  
  368. :: PREP JOB: Act on autorun flag. Skips safe mode checks, admin rights check, and EULA check. I assume if you use the auto flag (-a) you know what you're doing
  369. if /i %AUTORUN%==yes goto execute_jobs
  370.  
  371.  
  372. :: PREP JOB: Display the annoying disclaimer screen. Sigh
  373. cls
  374. setlocal enabledelayedexpansion
  375. if /i not %EULA_ACCEPTED%==yes (
  376.     color CF
  377.     echo  ************************** ANNOYING DISCLAIMER **************************
  378.     echo  * NOTE! By running Tron you accept COMPLETE responsibility for ANYTHING *
  379.     echo  * that happens. Although the chance of something bad happening due to   *
  380.     echo  * Tron is pretty remote, it's always a possibility, and Tron has ZERO   *
  381.     echo  * WARRANTY for ANY purpose. READ THE INSTRUCTIONS and understand you    *
  382.     echo  * run it AT YOUR OWN RISK.                                              *
  383.     echo  *                                                                       *
  384.     echo  * Tron.bat and all supporting code and scripts I've written are free    *
  385.     echo  * and open-source under the MIT License. All 3rd-party tools Tron calls *
  386.     echo  * ^(MBAM, TDSSK, etc^) are bound by their respective licenses. It is      *
  387.     echo  * YOUR RESPONSIBILITY to determine if you have the rights to use these  *
  388.     echo  * tools in whatever environment you use Tron in.                        *
  389.     echo  *                                                                       *
  390.     echo  * The bottom line is there is NO WARRANTY, you are ON YOUR OWN, and     *
  391.     echo  * anything that happens, good or bad, is YOUR RESPONSIBILITY.           *
  392.     echo  *************************************************************************
  393.     echo.
  394.     echo  Type I AGREE ^(all caps^) to accept this agreement and start Tron, or press
  395.     echo  ctrl^+c to cancel.
  396.     echo.
  397.     :eula_prompt
  398.     set /p CHOICE= Response:
  399.     if not "!CHOICE!"=="I AGREE" echo You must type I AGREE to continue&& goto eula_prompt
  400.     color 0f
  401.     )
  402. endlocal disabledelayedexpansion
  403.  
  404.  
  405. :: PREP JOB: UPM detection circuit #1
  406. if /i %UNICORN_POWER_MODE%==on (color DF) else (color 0f)
  407.  
  408.  
  409. ::::::::::::::::::::
  410. :: WELCOME SCREEN ::
  411. ::::::::::::::::::::
  412. cls
  413. echo  **********************  TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%)  *********************
  414. echo  * Script to automate a series of cleanup/disinfection tools           *
  415. echo  * Author: vocatus on reddit.com/r/TronScript                          *
  416. echo  *                                                                     *
  417. echo  * Stage:        Tools:                                                *
  418. echo  * ------------------------------------------------------------------- *
  419. echo  *  0 Prep:      rkill, PrcsKillr, TDSSK, reg bckup, SysRstr/VSS clean *
  420. echo  *  1 TempClean: TempFileCleanup, BlchBit, CCleaner,IE ^& EvtLogs clean *
  421. echo  *  2 De-bloat:  Remove OEM bloatware, remove Metro bloatware          *
  422. echo  *  3 Disinfect: RogueKiller, Sophos, Vipre, MBAM, DISM repair, SFC    *
  423. echo  *  4 Patch:     Update 7-Zip/Java/Flash/Windows, reset DISM base      *
  424. echo  *  5 Optimize:  chkdsk, defrag %SystemDrive% (mechanical disks only, no SSDs)    *
  425. echo  *  6 Wrap-up:   collect misc logs, send email report (if requested)   *
  426. echo  *                                                                     *
  427. echo  * \resources\stage_7_manual_tools contains additional tools which may *
  428. echo  * be run manually if necessary.                                       *
  429. echo  ***********************************************************************
  430. :: So ugly
  431. echo  Current settings (run tron.bat -c to dump full config):
  432. echo    Log location:            %LOGPATH%\%LOGFILE%
  433. if "%AUTO_REBOOT_DELAY%"=="0" (echo    Auto-reboot delay:       disabled) else (echo    Auto-reboot delay:      %AUTO_REBOOT_DELAY% seconds)
  434. if "%SSD_DETECTED%"=="yes" (echo    SSD detected?            %SSD_DETECTED% ^(defrag skipped^) ) else (echo    SSD detected?            %SSD_DETECTED%)
  435. if "%SAFE_MODE%"=="no" (
  436.         echo    Safe mode?               %SAFE_MODE% ^(not ideal^)
  437.     ) else (
  438.         if "%SAFEBOOT_OPTION%"=="MINIMAL" echo    Safe mode?               %SAFE_MODE%, without Networking
  439.         if "%SAFEBOOT_OPTION%"=="NETWORK" echo    Safe mode?               %SAFE_MODE%, with Networking ^(ideal^)
  440.     )
  441. if /i not "%SKIP_DEFRAG%"=="no" (
  442.     echo  ! SKIP_DEFRAG set^; skipping stage_5_optimize ^(defrag^)
  443.     echo    Runtime estimate:        4-6 hours
  444.     goto welcome_screen_trailer
  445.     )
  446. if "%SSD_DETECTED%"=="yes" (echo    Runtime estimate:        4-6 hours) else (echo    Runtime estimate:        6-8 hours)
  447. if /i %DRY_RUN%==yes echo  ! DRY_RUN set; will not execute any jobs
  448. if /i %UNICORN_POWER_MODE%==on echo  !! UNICORN POWER MODE ACTIVATED !!
  449. echo.
  450. :welcome_screen_trailer
  451. pause
  452.  
  453.  
  454. ::::::::::::::::::::::::
  455. :: EMAIL CONFIG CHECK ::
  456. ::::::::::::::::::::::::
  457. :: If -er flag was used or EMAIL_REPORT was set to yes, check for a correctly configured SwithMailSettings.xml
  458. setlocal enabledelayedexpansion
  459. if /i %EMAIL_REPORT%==yes (
  460.     pushd resources\stage_6_wrap-up\email_report
  461.     findstr "YOUR-PASSWORD-HERE" .\SwithMailSettings.xml >NUL
  462.     if !ERRORLEVEL!==0 (
  463.         color cf
  464.         cls
  465.         echo.
  466.         echo  ERROR
  467.         echo.
  468.         echo  You requested an email report ^(used the -er flag or set
  469.         echo  the EMAIL_REPORT variable to "yes"^) but didn't configure
  470.         echo  the settings file with your information. Update the following
  471.         echo  file with your SMTP username, password, etc:
  472.         echo.
  473.         echo  \resources\stage_6_wrap-up\email_report\SwithMailSettings.xml
  474.         echo.
  475.         echo  Alternatively you can run SwithMail.exe to have the GUI generate
  476.         echo  a config file for you.
  477.         pause
  478.     )
  479. popd
  480. )
  481. endlocal disabledelayedexpansion
  482.  
  483.  
  484. :::::::::::::::::::::
  485. :: SAFE MODE CHECK ::
  486. :::::::::::::::::::::
  487. :: Check if we're in safe mode
  488. if /i not "%SAFE_MODE%"=="yes" (
  489.         color 0c
  490.         cls
  491.         echo.
  492.         echo  WARNING
  493.         echo.
  494.         echo  The system is not in safe mode. Tron functions best
  495.         echo  in "Safe Mode with Networking" in order to download
  496.         echo  Windows and anti-virus updates.
  497.         echo.
  498.         echo  Tron should still run OK, but if you have infections
  499.         echo  or problems after running, recommend booting to
  500.         echo  "Safe Mode with Networking" and re-running.
  501.         echo.
  502.         pause
  503.         cls
  504.         )
  505.  
  506. :: Check if we have network support
  507. if /i "%SAFEBOOT_OPTION%"=="MINIMAL" (
  508.         color 0e
  509.         cls
  510.         echo.
  511.         echo  NOTE
  512.         echo.
  513.         echo  The system is in Safe Mode without Network support.
  514.         echo  Tron functions best in "Safe Mode with Networking" in
  515.         echo  order to download Windows and anti-virus updates.
  516.         echo.
  517.         echo  Tron will still function, but rebooting to "Safe Mode
  518.         echo  with Networking" is recommended.
  519.         echo.
  520.         pause
  521.         cls
  522.         )
  523.        
  524. ::::::::::::::::::::::::
  525. :: ADMIN RIGHTS CHECK ::
  526. ::::::::::::::::::::::::
  527. :: thanks to /u/agent-squirrel
  528. :: We skip this check if we're in Safe Mode because Safe Mode command prompts always start with Admin rights
  529. if /i not "%SAFE_MODE%"=="yes" (
  530.     net session >nul 2>&1
  531.     if /i not "%ERRORLEVEL%"=="0" (
  532.         color cf
  533.         cls
  534.         echo.
  535.         echo  ERROR
  536.         echo.
  537.         echo  Tron doesn't think it is running as an Administrator.
  538.         echo  Tron MUST be run with full Administrator rights to
  539.         echo  function correctly.
  540.         echo.
  541.         pause
  542.     )
  543. )
  544.  
  545.  
  546. ::::::::::::::::::
  547. :: EXECUTE JOBS ::
  548. ::::::::::::::::::
  549. :execute_jobs
  550. cls
  551. title TRON v%SCRIPT_VERSION% [stage_0_prep]
  552.  
  553. :: Make log directory and file if they don't already exist
  554. if /i not exist "%LOGPATH%" mkdir "%LOGPATH%"
  555. if /i not exist "%LOGPATH%\%LOGFILE%" echo. > "%LOGPATH%\%LOGFILE%"
  556.  
  557. :: UPM detection circuit #2
  558. if /i %UNICORN_POWER_MODE%==on (color DF) else (color 0f)
  559.  
  560. :: Create log header for this job
  561. echo ------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%
  562. echo -------------------------------------------------------------------------------
  563. echo  %CUR_DATE% %TIME%  TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%), %PROCESSOR_ARCHITECTURE% architecture>> %LOGPATH%\%LOGFILE%
  564. echo  %CUR_DATE% %TIME%  TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%), %PROCESSOR_ARCHITECTURE% architecture
  565. echo                          Executing as "%USERDOMAIN%\%USERNAME%" on %COMPUTERNAME%>> %LOGPATH%\%LOGFILE%
  566. echo                          Executing as "%USERDOMAIN%\%USERNAME%" on %COMPUTERNAME%
  567. echo                          Logfile:   %LOGPATH%\%LOGFILE%>> %LOGPATH%\%LOGFILE%
  568. echo                          Logfile:   %LOGPATH%\%LOGFILE%
  569. echo                          Command-line flags: %*>> %LOGPATH%\%LOGFILE%
  570. echo                          Command-line flags: %*
  571. echo                          Safe Mode: %SAFE_MODE% %SAFEBOOT_OPTION%>> %LOGPATH%\%LOGFILE%
  572. echo                          Safe Mode: %SAFE_MODE% %SAFEBOOT_OPTION%
  573. echo                          Free space before Tron run: %FREE_SPACE_BEFORE% MB>> %LOGPATH%\%LOGFILE%
  574. echo                          Free space before Tron run: %FREE_SPACE_BEFORE% MB
  575. echo ------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%
  576. echo -------------------------------------------------------------------------------
  577.  
  578.  
  579. :::::::::::::::::::
  580. :: STAGE 0: PREP ::
  581. :::::::::::::::::::
  582. :stage_0_prep
  583. pushd resources\stage_0_prep
  584. echo %CUR_DATE% %TIME%   Launch stage_0_prep jobs...>> "%LOGPATH%\%LOGFILE%"
  585. echo %CUR_DATE% %TIME%   Launch stage_0_prep jobs...
  586.  
  587.  
  588. :: JOB: rkill
  589. echo %CUR_DATE% %TIME%    Launch job 'rkill'...>> "%LOGPATH%\%LOGFILE%"
  590. echo %CUR_DATE% %TIME%    Launch job 'rkill'...
  591. pushd rkill
  592. if /i %DRY_RUN%==no (
  593.     explore.exe -s -l "%TEMP%\tron_rkill.log"
  594.     type "%TEMP%\tron_rkill.log" >> "%LOGPATH%\%LOGFILE%"
  595.     del "%TEMP%\tron_rkill.log"
  596.     if exist "%HOMEDRIVE%\%HOMEPATH%\Desktop\Rkill.txt" del "%HOMEDRIVE%\%HOMEPATH%\Desktop\Rkill.txt" 2>NUL
  597.     )
  598. popd
  599. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  600. echo %CUR_DATE% %TIME%    Done.
  601.  
  602.  
  603. :: JOB: ProcessKiller
  604. echo %CUR_DATE% %TIME%    Launch Job 'ProcessKiller'...>> "%LOGPATH%\%LOGFILE%"
  605. echo %CUR_DATE% %TIME%    Launch Job 'ProcessKiller'...
  606. pushd processkiller
  607. if /i %DRY_RUN%==no ProcessKiller.exe
  608. popd
  609. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  610. echo %CUR_DATE% %TIME%    Done.
  611.  
  612.  
  613. :: JOB: Backup registry
  614. echo %CUR_DATE% %TIME%    Backing up registry to "%LOGPATH%"...>> "%LOGPATH%\%LOGFILE%"
  615. echo %CUR_DATE% %TIME%    Backing up registry to "%LOGPATH%"...
  616. pushd backup_registry
  617. if /i %DRY_RUN%==no erunt "%LOGPATH%\tron_registry_backup" /noconfirmdelete /noprogresswindow
  618. popd
  619. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  620. echo %CUR_DATE% %TIME%    Done.
  621.  
  622.  
  623. :: JOB: TDSS Killer
  624. echo %CUR_DATE% %TIME%    Launch job 'TDSSKiller'...>> "%LOGPATH%\%LOGFILE%"
  625. echo %CUR_DATE% %TIME%    Launch job 'TDSSKiller'...
  626. pushd tdss_killer
  627. if /i %DRY_RUN%==no (
  628.     "TDSSKiller v3.0.0.41.exe" -l %TEMP%\tdsskiller.log -silent -tdlfs -dcexact -accepteula -accepteulaksn
  629.     :: Copy TDSSKiller log into the main Tron log
  630.     type "%TEMP%\tdsskiller.log" >> "%LOGPATH%\%LOGFILE%"
  631.     del "%TEMP%\tdsskiller.log" 2>NUL
  632.     )
  633. popd
  634. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  635. echo %CUR_DATE% %TIME%    Done.
  636.  
  637.  
  638. :: JOB: Purge oldest shadow copies
  639. echo %CUR_DATE% %TIME%    Purging oldest Shadow Copy set (7 and up)...>> "%LOGPATH%\%LOGFILE%"
  640. echo %CUR_DATE% %TIME%    Purging oldest Shadow Copy set (7 and up)...
  641. pushd purge_shadow_copies
  642. :: Read 9 characters into the WIN_VER variable. Only versions of Windows older than Vista had "Microsoft" as the first part of their title,
  643. :: So if we don't find "Microsoft" in the first 9 characters we can safely assume we're not on XP/2k3
  644. :: Then we check for Vista, because vssadmin on Vista doesn't support deleting old copies. Sigh.
  645. if /i not "%WIN_VER:~0,9%"=="Microsoft" (
  646.     if /i not "%WIN_VER:~0,9%"=="Windows V" (
  647.         if /i %DRY_RUN%==no (
  648.             :: Force allow us to start VSS service in Safe Mode
  649.             reg add "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\%SAFEBOOT_OPTION%\VSS" /ve /t reg_sz /d Service /f 2>NUL
  650.             net start VSS >NUL
  651.             vssadmin delete shadows /for=%SystemDrive% /oldest /quiet 2>NUL
  652.             )
  653.         )
  654.     )
  655. popd
  656. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  657. echo %CUR_DATE% %TIME%    Done.
  658.  
  659.  
  660. :: JOB: Disable sleep mode
  661. echo %CUR_DATE% %TIME%    Disabling Sleep mode...>> "%LOGPATH%\%LOGFILE%"
  662. echo %CUR_DATE% %TIME%    Disabling Sleep mode...
  663. pushd disable_sleep
  664. if /i %DRY_RUN%==yes goto skip_disable_sleep
  665.  
  666. echo %CUR_DATE% %TIME%    Exporting current power scheme and switching to Always On...>> "%LOGPATH%\%LOGFILE%"
  667. echo %CUR_DATE% %TIME%    Exporting current power scheme and switching to Always On...
  668.  
  669. :: Export the current power scheme to a file. Thanks to reddit.com/user/GetOnMyAmazingHorse
  670. setlocal enabledelayedexpansion
  671. :: Windows XP version
  672. if "%WIN_VER%"=="Microsoft Windows XP" (
  673.     :: Extract the line containing the current power GUID
  674.     for /f "delims=^T" %%i in ('powercfg -query ^| find /i "Name"') do (set t=%%i)
  675.     :: Parse out just the name and stash it in a variable
  676.     set POWER_SCHEME=!t:~27!
  677.     :: Export the power scheme based on this GUID
  678.     powercfg /EXPORT "!POWER_SCHEME!" /FILE %LOGPATH%\tron_power_config_backup.pow
  679.     :: Set the "High Performance" scheme active
  680.     powercfg /SETACTIVE "Always On"
  681.     )
  682.  
  683. :: Windows Server 2003 version
  684. if "%WIN_VER%"=="Microsoft Windows Server 2003" (
  685.     :: Extract the line containing the current power GUID
  686.     for /f "delims=^T" %%i in ('powercfg -query ^| find /i "Name"') do (set t=%%i)
  687.     :: Parse out just the name and stash it in a variable
  688.     set POWER_SCHEME=!t:~27!
  689.     :: Export the power scheme based on this GUID
  690.     powercfg /EXPORT "!POWER_SCHEME!" /FILE %LOGPATH%\tron_power_config_backup.pow
  691.     :: Set the "High Performance" scheme active
  692.     powercfg /SETACTIVE "Always On"
  693. ) else (
  694.     :: This version of the command executes if we're not on XP or Server 2003
  695.     :: Extract the line containing the current power GUID
  696.     for /f "delims=" %%i in ('powercfg -list ^| find "*"') do (set t=%%i)
  697.     :: Parse out just the GUID and stash it in a variable
  698.     set POWER_SCHEME=!t:~19,36!
  699.     :: Export the power scheme based on this GUID
  700.     powercfg /EXPORT %LOGPATH%\tron_power_config_backup.pow !POWER_SCHEME!
  701.     :: Set the "High Performance" scheme active
  702.     powercfg /SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  703.     )
  704.  
  705. :: This cheats a little bit by stacking the set command on the same line as the endlocal so it executes immediately after ENDLOCAL but before the variable gets wiped
  706.  
  707. out by the endlocal. Kind of a little trick to get a SETLOCAL-internal variable exported to a global script-wide variable.
  708. :: We need the POWER_SCHEME GUID for later when we re-import everything
  709. endlocal disabledelayedexpansion && set POWER_SCHEME=%POWER_SCHEME%
  710.  
  711. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  712. echo %CUR_DATE% %TIME%    Done.
  713.  
  714. :skip_disable_sleep
  715. popd
  716. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  717. echo %CUR_DATE% %TIME%    Done.
  718.  
  719.  
  720. :: JOB: Check and Repair WMI if it's broken
  721. echo %CUR_DATE% %TIME%    Checking WMI...>> "%LOGPATH%\%LOGFILE%"
  722. echo %CUR_DATE% %TIME%    Checking WMI...
  723. pushd repair_wmi
  724. if /i %DRY_RUN%==yes goto skip_repair_wmi
  725.  
  726. :: Do a quick check to make sure WMI is working, and if not, repair it
  727. %WMIC% timezone >NUL
  728. if /i not %ERRORLEVEL%==0 (
  729.     echo %CUR_DATE% %TIME% !  WMI appears to be broken. Running WMI repair. This might take a minute, please be patient...>> "%LOGPATH%\%LOGFILE%"
  730.     echo %CUR_DATE% %TIME% !  WMI appears to be broken. Running WMI repair. This might take a minute, please be patient...
  731.     net stop winmgmt
  732.     pushd %SystemRoot%\system32\wbem
  733.     for %%i in (*.dll) do RegSvr32 -s %%i
  734.    :: Kill this random window that pops up
  735.     tskill wbemtest /a 2>NUL
  736.     scrcons.exe /RegServer
  737.     unsecapp.exe /RegServer
  738.     start "" wbemtest.exe /RegServer
  739.     tskill wbemtest /a 2>NUL
  740.     tskill wbemtest /a 2>NUL
  741.    :: winmgmt.exe /resetrepository       -- optional; force full rebuild instead of repair like the line below this. Enable if you're feeling REAAAALLY crazy
  742.     winmgmt.exe /salvagerepository /resyncperf
  743.     wmiadap.exe /RegServer
  744.     wmiapsrv.exe /RegServer
  745.     wmiprvse.exe /RegServer
  746.    :: Get the 64-bit versions if they exist
  747.     if exist %SystemRoot%\SysWOW64\wbem (
  748.         pushd %SystemRoot%\SysWOW64\wbem
  749.         for %%j in (*.dll) do RegSvr32 -s %%j
  750.         winmgmt.exe /salvagerepository /resyncperf
  751.         wmiadap.exe /RegServer
  752.         wmiprvse.exe /RegServer
  753.         popd
  754.         )
  755.     net start winmgmt
  756.     popd
  757.     )
  758.  
  759. :skip_repair_wmi
  760. popd
  761. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  762. echo %CUR_DATE% %TIME%    Done.
  763.  
  764. :: JOB: Reduce SysRestore space
  765. echo %CUR_DATE% %TIME%    Reducing max allowed System Restore space to 7%% of disk...>> "%LOGPATH%\%LOGFILE%"
  766. echo %CUR_DATE% %TIME%    Reducing max allowed System Restore space to 7%% of disk...
  767. pushd reduce_system_restore
  768. if /i %DRY_RUN%==no (
  769.     %SystemRoot%\System32\reg.exe add "\\%COMPUTERNAME%\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DiskPercent /t REG_DWORD /d 00000007
  770.  
  771. /f>> "%LOGPATH%\%LOGFILE%"
  772.     %SystemRoot%\System32\reg.exe add "\\%COMPUTERNAME%\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\Cfg" /v DiskPercent /t REG_DWORD /d
  773.  
  774. 00000007 /f>> "%LOGPATH%\%LOGFILE%"
  775.     )
  776. popd
  777. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  778. echo %CUR_DATE% %TIME%    Done.
  779.  
  780.  
  781. popd
  782. echo %CUR_DATE% %TIME%   Completed stage_0_prep jobs.>> "%LOGPATH%\%LOGFILE%"
  783. echo %CUR_DATE% %TIME%   Completed stage_0_prep jobs.
  784.  
  785.  
  786. ::::::::::::::::::::::::
  787. :: STAGE 1: TEMPCLEAN ::
  788. ::::::::::::::::::::::::
  789. :stage_1_tempclean
  790. title TRON v%SCRIPT_VERSION% [stage_1_tempclean]
  791. pushd resources\stage_1_tempclean
  792. echo %CUR_DATE% %TIME%   Launch stage_1_tempclean jobs...>> "%LOGPATH%\%LOGFILE%"
  793. echo %CUR_DATE% %TIME%   Launch stage_1_tempclean jobs...
  794.  
  795.  
  796. :: JOB: Clean Internet Explorer; Windows' built-in method
  797. echo %CUR_DATE% %TIME%    Launch job 'Clean Internet Explorer'...>> "%LOGPATH%\%LOGFILE%"
  798. echo %CUR_DATE% %TIME%    Launch job 'Clean Internet Explorer'...
  799. pushd clean_internet_explorer
  800. if /i %DRY_RUN%==no rundll32.exe inetcpl.cpl,ClearMyTracksByProcess 4351
  801. popd
  802. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  803. echo %CUR_DATE% %TIME%    Done.
  804.  
  805.  
  806. :: JOB: TempFileCleanup.bat
  807. echo %CUR_DATE% %TIME%    Launch job 'TempFileCleanup'...>> "%LOGPATH%\%LOGFILE%"
  808. echo %CUR_DATE% %TIME%    Launch job 'TempFileCleanup'...
  809. pushd tempfilecleanup
  810. if /i %DRY_RUN%==no call TempFileCleanup.bat>> "%LOGPATH%\%LOGFILE%" 2>NUL
  811. :: Reset window title since TempeFileCleanup clobbers it
  812. title TRON v%SCRIPT_VERSION% [stage_1_tempclean]
  813. popd
  814. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  815. echo %CUR_DATE% %TIME%    Done.
  816.  
  817.  
  818. :: JOB: CCLeaner
  819. echo %CUR_DATE% %TIME%    Launch job 'CCleaner'...>> "%LOGPATH%\%LOGFILE%"
  820. echo %CUR_DATE% %TIME%    Launch job 'CCleaner'...
  821. pushd ccleaner
  822. if /i %DRY_RUN%==no (
  823.     ccleaner.exe /auto>> "%LOGPATH%\%LOGFILE%" 2>NUL
  824.     ping 127.0.0.1 -n 12 >NUL
  825.     )
  826. popd
  827. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  828. echo %CUR_DATE% %TIME%    Done.
  829.  
  830.  
  831. :: JOB: BleachBit
  832. echo %CUR_DATE% %TIME%    Launch job 'BleachBit'...>> "%LOGPATH%\%LOGFILE%"
  833. echo %CUR_DATE% %TIME%    Launch job 'BleachBit'...
  834. pushd bleachbit
  835. if /i %DRY_RUN%==no (
  836.     bleachbit_console.exe --preset -c>> "%LOGPATH%\%LOGFILE%" 2>NUL
  837.     ping 127.0.0.1 -n 12 >NUL
  838.     )
  839. popd
  840. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  841. echo %CUR_DATE% %TIME%    Done.
  842.  
  843.  
  844. :: JOB: Clear Windows event logs
  845. echo %CUR_DATE% %TIME%    Launch job 'Clear Windows event logs'...>> "%LOGPATH%\%LOGFILE%"
  846. echo %CUR_DATE% %TIME%    Launch job 'Clear Windows event logs'...
  847. pushd backup_and_clear_windows_event_logs
  848. :: Make a subdirectory in the logpath for the Windows event log backups
  849. if /i not exist "%LOGPATH%\tron_event_log_backups" mkdir "%LOGPATH%\tron_event_log_backups"
  850. echo %CUR_DATE% %TIME%    Saving logs to "%LOGPATH%\tron_event_log_backups" first...>> "%LOGPATH%\%LOGFILE%"
  851. echo %CUR_DATE% %TIME%    Saving logs to "%LOGPATH%\tron_event_log_backups" first...
  852. :: Backup all logs first. We redirect error output to NUL (2>nul) because due to the way WMI formats lists, there is
  853. :: a trailing blank line which messes up the last iteration of the FOR loop, but we can safely suppress errors from it
  854. setlocal enabledelayedexpansion
  855. if /i %DRY_RUN%==no for /f %%i in ('%WMIC% nteventlog where "filename like '%%'" list instance') do %WMIC% nteventlog where "filename like '%%%%i%%'" backupeventlog
  856.  
  857. "%LOGPATH%\tron_event_log_backups\%%i.evt" >> "%LOGPATH%\%LOGFILE%" 2>NUL
  858. endlocal disabledelayedexpansion
  859. echo %CUR_DATE% %TIME%    Backups done, now clearing...>> "%LOGPATH%\%LOGFILE%"
  860. echo %CUR_DATE% %TIME%    Backups done, now clearing...
  861. :: Now we clear the logs
  862. if /i %DRY_RUN%==no %WMIC% nteventlog where "filename like '%%'" cleareventlog >> "%LOGPATH%\%LOGFILE%"
  863. :: Alternate Vista-and-up only method
  864. :: if /i %DRY_RUN%==no for /f %%x in ('wevtutil el') do wevtutil cl "%%x" 2>NUL
  865.  
  866. popd
  867. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  868. echo %CUR_DATE% %TIME%    Done.
  869.  
  870.  
  871. :: JOB: Clear Windows Update cache
  872. echo %CUR_DATE% %TIME%    Launch job 'Clear Windows Update cache'...>> "%LOGPATH%\%LOGFILE%"
  873. echo %CUR_DATE% %TIME%    Launch job 'Clear Windows Update cache'...
  874. pushd clear_windows_update_cache
  875. if /i %DRY_RUN%==no (
  876.     :: Allow us to start the service in Safe Mode. Thanks to /u/GrizzlyWinter
  877.     reg add "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\%SAFEBOOT_OPTION%\WUAUSERV" /ve /t reg_sz /d Service /f 2>NUL
  878.     net stop WUAUSERV >> "%LOGPATH%\%LOGFILE%"
  879.     if exist %windir%\softwaredistribution\download rmdir /s /q %windir%\softwaredistribution\download >> "%LOGPATH%\%LOGFILE%"
  880.     net start WUAUSERV >> "%LOGPATH%\%LOGFILE%"
  881.     )
  882. popd
  883. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  884. echo %CUR_DATE% %TIME%    Done.
  885.    
  886.    
  887. popd
  888. echo %CUR_DATE% %TIME%   Completed stage_1_tempclean jobs.>> "%LOGPATH%\%LOGFILE%"
  889. echo %CUR_DATE% %TIME%   Completed stage_1_tempclean jobs.
  890.  
  891.  
  892. :::::::::::::::::::::::
  893. :: STAGE 2: De-Bloat ::
  894. :::::::::::::::::::::::
  895. :stage_2_de-bloat
  896. title TRON v%SCRIPT_VERSION% [stage_2_de-bloat]
  897. if %SKIP_DEBLOAT%==yes (
  898.     echo %CUR_DATE% %TIME% ! SKIP_DEBLOAT ^(-sb^) set, skipping Stage 2 jobs...>> "%LOGPATH%\%LOGFILE%"
  899.     echo %CUR_DATE% %TIME% ! SKIP_DEBLOAT ^(-sb^) set, skipping Stage 2 jobs...
  900.     goto skip_debloat
  901.     )
  902.  
  903. pushd resources\stage_2_de-bloat
  904. echo %CUR_DATE% %TIME%   Launch stage_2_de-bloat jobs...>> "%LOGPATH%\%LOGFILE%"
  905. echo %CUR_DATE% %TIME%   Launch stage_2_de-bloat jobs...
  906.  
  907. :: JOB: Remove crapware programs
  908. pushd oem
  909. echo %CUR_DATE% %TIME%    Attempting to remove common OEM junkware programs...>> "%LOGPATH%\%LOGFILE%"
  910. echo %CUR_DATE% %TIME%    Attempting to remove common OEM junkware programs...
  911. echo %CUR_DATE% %TIME%    Customize list here: \resources\stage_2_de-bloat\oem\programs_to_target.txt>> "%LOGPATH%\%LOGFILE%"
  912. echo %CUR_DATE% %TIME%    Customize list here: \resources\stage_2_de-bloat\oem\programs_to_target.txt
  913. :: This searches through the list of programs in "programs_to_target.txt" file and uninstalls them one-by-one
  914. if /i %DRY_RUN%==no FOR /F "tokens=*" %%i in (programs_to_target.txt) DO echo   %%i && echo   %%i...>> "%LOGPATH%\%LOGFILE%" && %WMIC% product where "name like '%
  915.  
  916. %i'" uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
  917.  
  918. popd
  919. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  920. echo %CUR_DATE% %TIME%    Done.
  921.  
  922.  
  923. :: JOB: Remove default Metro apps (Windows 8/8.1/2012/2012-R2 only). Thanks to https://keybase.io/exabrial
  924. pushd win8_metro_apps
  925. :: Read nine characters into the WIN_VER variable (starting at position 0 on the left) to check for Windows 8; 16 characters in to check for Server 2012.
  926. :: The reason we read partially into the variable instead of comparing the whole thing is because we don't care what sub-version of 8/2012 we're on.
  927. :: Also I'm lazy and don't want to write ten different comparisons for all the random sub-versions MS churns out with inconsistent names.
  928. if "%WIN_VER:~0,9%"=="Windows 8" set TARGET_METRO=yes
  929. if "%WIN_VER:~0,18%"=="Windows Server 201" set TARGET_METRO=yes
  930. :: Check if we're forcefully skipping Metro de-bloat. Thanks to /u/swtester for the suggestion
  931. if %PRESERVE_METRO_APPS%==yes set TARGET_METRO=no
  932. if /i %TARGET_METRO%==yes (
  933.     echo %CUR_DATE% %TIME%    "%WIN_VER%" detected, removing default Metro apps...>> "%LOGPATH%\%LOGFILE%"
  934.     echo %CUR_DATE% %TIME%    "%WIN_VER%" detected, removing default Metro apps...
  935.     :: Force allowing us to start AppXSVC service in Safe Mode. AppXSVC is the MSI Installer equivalent for "apps" (vs. programs)
  936.     if /i %DRY_RUN%==no (
  937.         reg add "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\%SAFEBOOT_OPTION%\AppXSVC" /ve /t reg_sz /d Service /f
  938.         net start AppXSVC
  939.         :: Enable scripts in PowerShell
  940.         powershell "Set-ExecutionPolicy Unrestricted -force 2>&1 | Out-Null"
  941.         :: Call PowerShell to run the commands
  942.         powershell "Get-AppXProvisionedPackage -online | Remove-AppxProvisionedPackage -online 2>&1 | Out-Null"
  943.         powershell "Get-AppxPackage -AllUsers | Remove-AppxPackage 2>&1 | Out-Null"
  944.         )
  945.     echo %CUR_DATE% %TIME%    Running DISM cleanup against unused App binaries...>> "%LOGPATH%\%LOGFILE%"
  946.     echo %CUR_DATE% %TIME%    Running DISM cleanup against unused App binaries...
  947.     :: Thanks to reddit.com/user/nommaddave
  948.     if /i %DRY_RUN%==no Dism /Online /Cleanup-Image /StartComponentCleanup /Logpath:"%LOGPATH%\tron_dism.log"
  949.     echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  950.     echo %CUR_DATE% %TIME%    Done.
  951.     )
  952.     popd
  953.  
  954.  
  955. popd
  956. echo %CUR_DATE% %TIME%   Completed stage_2_de-bloat jobs.>> "%LOGPATH%\%LOGFILE%"
  957. echo %CUR_DATE% %TIME%   Completed stage_2_de-bloat jobs.
  958. :skip_debloat
  959.  
  960.  
  961. ::::::::::::::::::::::::
  962. :: STAGE 3: Disinfect ::
  963. ::::::::::::::::::::::::
  964. :stage_3_disinfect
  965. title TRON v%SCRIPT_VERSION% [stage_3_disinfect]
  966. pushd resources\stage_3_disinfect
  967. echo %CUR_DATE% %TIME%   Launch stage_3_disinfect jobs...>> "%LOGPATH%\%LOGFILE%"
  968. echo %CUR_DATE% %TIME%   Launch stage_3_disinfect jobs...
  969.  
  970.  
  971. :: JOB: RogueKiller
  972. :: Thanks to /u/bodkov for suggestion
  973. echo %CUR_DATE% %TIME%    Launch job 'RogueKiller' (slow, be patient)...>> "%LOGPATH%\%LOGFILE%"
  974. echo %CUR_DATE% %TIME%    Launch job 'RogueKiller' (slow, be patient)...
  975. pushd roguekiller
  976. if /i %DRY_RUN%==no (
  977.     if /i %VERBOSE%==yes echo remove| RogueKillerCMD.exe -scan remove
  978.     if /i %VERBOSE%==no echo remove| RogueKillerCMD.exe -scan remove >> "%LOGPATH%\%LOGFILE%"
  979.     )
  980. popd
  981. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  982. echo %CUR_DATE% %TIME%    Done.
  983.  
  984.  
  985. :: JOB: Check for the -sa flag (skip antivirus scans) and skip Sophos, Vipre and MBAM if used
  986. if /i %SKIP_ANTIVIRUS_SCANS%==yes (
  987.     echo %CUR_DATE% %TIME%   SKIP_ANTIVIRUS_SCANS set. Skipping Sophos, Vipre and MBAM scans...>> "%LOGPATH%\%LOGFILE%"
  988.     echo %CUR_DATE% %TIME%   SKIP_ANTIVIRUS_SCANS set. Skipping Sophos, Vipre and MBAM scans...
  989.     goto skip_antivirus_scans
  990.     )
  991.  
  992.  
  993. :: JOB: Sophos Virus Remover
  994. echo %CUR_DATE% %TIME%    Launch job 'Sophos Virus Removal Tool' (slow, be patient)...>> "%LOGPATH%\%LOGFILE%"
  995. echo %CUR_DATE% %TIME%    Launch job 'Sophos Virus Removal Tool' (slow, be patient)...
  996. pushd sophos_virus_remover
  997. if /i %DRY_RUN%==no (
  998.     if exist %ProgramData%\Sophos\Sophos Virus Removal Tool\Logs\SophosVirusRemovalTool.log del /f /q %ProgramData%\Sophos\Sophos Virus Removal Tool\Logs
  999.  
  1000. \SophosVirusRemovalTool.log 2>NUL
  1001.     if /i %VERBOSE%==no svrtcli.exe -yes
  1002.     if /i %VERBOSE%==yes svrtcli.exe -yes -debug
  1003.     type %ProgramData%\Sophos\Sophos Virus Removal Tool\Logs\SophosVirusRemovalTool.log >> "%LOGPATH%\%LOGFILE%"
  1004.     )
  1005. popd
  1006. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1007. echo %CUR_DATE% %TIME%    Done.
  1008.  
  1009.  
  1010. :: JOB: VIPRE Rescue
  1011. :: Haven't been able to figure out where Vipre saves its log file to, so we can't grab it like with do with Sophos above
  1012. echo %CUR_DATE% %TIME%    Launch job 'Vipre rescue scanner' (slow, be patient)...>> "%LOGPATH%\%LOGFILE%"
  1013. echo %CUR_DATE% %TIME%    Launch job 'Vipre rescue scanner' (slow, be patient)...
  1014. pushd vipre_rescue
  1015. if /i %DRY_RUN%==no (
  1016.     if /i %VERBOSE%==no VipreRescueScanner.exe /nolog
  1017.     if /i %VERBOSE%==yes VipreRescueScanner.exe
  1018.     )
  1019. popd
  1020. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1021. echo %CUR_DATE% %TIME%    Done.
  1022.  
  1023.  
  1024. :: JOB: MBAM (MalwareBytes Anti-Malware)
  1025. if %SKIP_MBAM_ONLY%==yes (
  1026.     echo %CUR_DATE% %TIME% ! SKIP_MBAM_ONLY ^(-smbam^) set, skipping Malwarebytes...>> "%LOGPATH%\%LOGFILE%"
  1027.     echo %CUR_DATE% %TIME% ! SKIP_MBAM_ONLY ^(-smbam^) set, skipping Malwarebytes...
  1028.     goto skip_mbam
  1029.     )
  1030. echo %CUR_DATE% %TIME%    Launch job 'Malwarebytes Anti-Malware', continuing other jobs...>>"%LOGPATH%\%LOGFILE%"
  1031. echo %CUR_DATE% %TIME%    Launch job 'Malwarebytes Anti-Malware', continuing other jobs...
  1032. pushd mbam
  1033. :: Install MBAM & remove the desktop icon
  1034. if /i %DRY_RUN%==no (
  1035.     "Malwarebytes Anti-Malware v2.0.4.1028.exe" /verysilent
  1036.     ::"Malwarebytes Anti-Malware v1.75.0.1300.exe" /SP- /VERYSILENT /NORESTART /SUPPRESSMSGBOXES /NOCANCEL
  1037.     if exist "%PUBLIC%\Desktop\Malwarebytes Anti-Malware.lnk" del "%PUBLIC%\Desktop\Malwarebytes Anti-Malware.lnk"
  1038.     if exist "%USERPROFILE%\Desktop\Malwarebytes Anti-Malware.lnk" del "%USERPROFILE%\Desktop\Malwarebytes Anti-Malware.lnk"
  1039.     if exist "%ALLUSERSPROFILE%\Desktop\Malwarebytes Anti-Malware.lnk" del "%ALLUSERSPROFILE%\Desktop\Malwarebytes Anti-Malware.lnk"
  1040.  
  1041.     :: Scan for and launch appropriate architecture version
  1042.     if exist "%ProgramFiles(x86)%\Malwarebytes Anti-Malware" (
  1043.         pushd "%ProgramFiles(x86)%\Malwarebytes Anti-Malware"
  1044.     ) else (
  1045.         pushd "%ProgramFiles%\Malwarebytes Anti-Malware"
  1046.         )
  1047.     start "" "mbam.exe"
  1048.     popd
  1049. )
  1050. :skip_mbam
  1051.  
  1052. popd
  1053. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1054. echo %CUR_DATE% %TIME%    Done.
  1055. :skip_antivirus_scans
  1056.  
  1057.  
  1058. :: JOB: Check Windows Image for corruptions before running SFC (Windows 8/2012 only)
  1059. :: Thanks to /u/nomaddave
  1060. echo %CUR_DATE% %TIME%    Launch job 'Dism Windows image check (Win8/2012 only)'...>> "%LOGPATH%\%LOGFILE%"
  1061. echo %CUR_DATE% %TIME%    Launch job 'Dism Windows image check (Win8/2012 only)'...
  1062. pushd dism_image_check
  1063. if /i %DRY_RUN%==yes goto skip_dism_image_check
  1064.  
  1065. :: Read WIN_VER and run the scan if we're on some derivative of 8 or 2012
  1066. if "%WIN_VER:~0,9%"=="Windows Server 2012" (
  1067.     Dism /Online /NoRestart /Cleanup-Image /ScanHealth /Logpath:"%LOGPATH%\tron_dism.log"
  1068.     type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  1069.     )
  1070. if "%WIN_VER:~0,9%"=="Windows 8" (
  1071.     Dism /Online /NoRestart /Cleanup-Image /ScanHealth /Logpath:"%LOGPATH%\tron_dism.log"
  1072.     type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  1073.     )
  1074.  
  1075. :: If we detect errors, try to repair them
  1076. if /i not %ERRORLEVEL%==0 (
  1077.     if "%WIN_VER:~0,9%"=="Windows Server 2012" (
  1078.         echo %CUR_DATE% %TIME% !  DISM: Image corruption detected. Attempting repair...>> "%LOGPATH%\%LOGFILE%"
  1079.         echo %CUR_DATE% %TIME% !  DISM: Image corruption detected. Attempting repair...
  1080.         :: Add /LimitAccess flag to this command to prevent connecting to Windows Update for replacement files
  1081.         Dism /Online /NoRestart /Cleanup-Image /RestoreHealth /Logpath:"%LOGPATH%\tron_dism.log"
  1082.         type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  1083.         )
  1084.     if "%WIN_VER:~0,9%"=="Windows 8" (
  1085.         echo %CUR_DATE% %TIME% !  DISM: Image corruption detected. Attempting repair...>> "%LOGPATH%\%LOGFILE%"
  1086.         echo %CUR_DATE% %TIME% !  DISM: Image corruption detected. Attempting repair...
  1087.         :: Add /LimitAccess flag to this command to prevent connecting to Windows Update for replacement files
  1088.         Dism /Online /NoRestart /Cleanup-Image /RestoreHealth /Logpath:"%LOGPATH%\tron_dism.log"
  1089.         type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  1090.     ) else (
  1091.         echo %CUR_DATE% %TIME%    DISM: No image corruption detected.>> "%LOGPATH%\%LOGFILE%"
  1092.         echo %CUR_DATE% %TIME%    DISM: No image corruption detected.
  1093.         )
  1094.     )
  1095.  
  1096. :skip_dism_image_check
  1097. popd
  1098. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1099. echo %CUR_DATE% %TIME%    Done.
  1100.  
  1101.  
  1102. :: JOB: System File Checker (SFC) scan
  1103. echo %CUR_DATE% %TIME%    Launch job 'System File Checker'...>> "%LOGPATH%\%LOGFILE%"
  1104. echo %CUR_DATE% %TIME%    Launch job 'System File Checker'...
  1105. pushd sfc
  1106. if /i %DRY_RUN%==yes goto skip_sfc
  1107. :: Basically this says "If OS is NOT XP or 2003, go ahead and run system file checker"
  1108. if /i not "%WIN_VER:~0,9%"=="Microsoft" %SystemRoot%\System32\sfc.exe /scannow
  1109. :: Dump the SFC log into the Tron log. Thanks to reddit.com/user/adminhugh
  1110. %SystemRoot%\System32\findstr.exe /c:"[SR]" %SystemRoot%\logs\cbs\cbs.log>> "%LOGPATH%\%LOGFILE%"
  1111. :skip_sfc
  1112. popd
  1113. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1114. echo %CUR_DATE% %TIME%    Done.
  1115.  
  1116.  
  1117. popd
  1118. echo %CUR_DATE% %TIME%   Completed stage_3_disinfect jobs.>> "%LOGPATH%\%LOGFILE%"
  1119. echo %CUR_DATE% %TIME%   Completed stage_3_disinfect jobs.
  1120.  
  1121.  
  1122. :: Since this whole section takes a long time to run, set the date again in case we crossed over midnight during the scans.
  1123. :: This is a half-hearted fix for now. Thanks to /u/ScubaSteve for finding the bug.
  1124. FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
  1125. set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
  1126.  
  1127.  
  1128. ::::::::::::::::::::::
  1129. :: STAGE 4: Patches ::
  1130. ::::::::::::::::::::::
  1131. :stage_4_patch
  1132. title TRON v%SCRIPT_VERSION% [stage_4_patch]
  1133. pushd resources\stage_4_patch
  1134. echo %CUR_DATE% %TIME%   Launch stage_4_patch jobs...>> "%LOGPATH%\%LOGFILE%"
  1135. echo %CUR_DATE% %TIME%   Launch stage_4_patch jobs...
  1136.  
  1137.  
  1138. :: Prep task: enable MSI installer in Safe Mode
  1139. if /i %DRY_RUN%==no (
  1140.     reg add "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\%SAFEBOOT_OPTION%\MSIServer" /ve /t reg_sz /d Service /f
  1141.     net start msiserver
  1142.     )
  1143.  
  1144.    
  1145. :: Check for skip patches (-sp) flag or variable and skip to Windows Update if used
  1146. if /i %SKIP_PATCHES%==yes (
  1147.     echo %CUR_DATE% %TIME%    SKIP_PATCHES set to "%SKIP_DEFRAG%". Skipping app patches...>> "%LOGPATH%\%LOGFILE%"
  1148.     echo %CUR_DATE% %TIME%    SKIP_PATCHES set to "%SKIP_DEFRAG%". Skipping app patches...
  1149.     goto skip_patches
  1150.     )
  1151.    
  1152.  
  1153. :: JOB: 7-Zip
  1154. echo %CUR_DATE% %TIME%    Launch job 'Update 7-Zip'...>> "%LOGPATH%\%LOGFILE%"
  1155. echo %CUR_DATE% %TIME%    Launch job 'Update 7-Zip'...
  1156.  
  1157. :: Check if we're on 32-bit Windows and run the appropriate architecture installer
  1158. if /i %DRY_RUN%==yes goto skip_7-Zip
  1159. if /i '%PROCESSOR_ARCHITECTURE%'=='x86' (
  1160.     pushd 7-Zip\v9.20\x86
  1161.     setlocal
  1162.     call "7-Zip v9.20 x86.bat"
  1163.     endlocal
  1164.     popd
  1165. ) else (
  1166.     pushd 7-Zip\v9.20\x64
  1167.     setlocal
  1168.     call "7-Zip v9.20 x64.bat"
  1169.     endlocal
  1170.     popd
  1171.     )
  1172. :skip_7-Zip
  1173. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1174. echo %CUR_DATE% %TIME%    Done.
  1175.  
  1176. :: JOB: Adobe Flash Player
  1177. echo %CUR_DATE% %TIME%    Launch job 'Update Adobe Flash Player'...>> "%LOGPATH%\%LOGFILE%"
  1178. echo %CUR_DATE% %TIME%    Launch job 'Update Adobe Flash Player'...
  1179. pushd "adobe\flash_player\firefox"
  1180. setlocal
  1181. if /i %DRY_RUN%==no call "Adobe Flash Player (Firefox).bat"
  1182. endlocal
  1183. popd
  1184. pushd "adobe\flash_player\internet explorer"
  1185. setlocal
  1186. if /i %DRY_RUN%==no call "Adobe Flash Player (IE).bat"
  1187. endlocal
  1188. popd
  1189. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1190. echo %CUR_DATE% %TIME%    Done.
  1191.  
  1192. :: JOB: Adobe Reader
  1193. echo %CUR_DATE% %TIME%    Launch job 'Update Adobe Reader'...>> "%LOGPATH%\%LOGFILE%"
  1194. echo %CUR_DATE% %TIME%    Launch job 'Update Adobe Reader'...
  1195. pushd adobe\reader\x86
  1196. setlocal
  1197. if /i %DRY_RUN%==no call "Adobe Reader.bat"
  1198. endlocal
  1199. popd
  1200. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1201. echo %CUR_DATE% %TIME%    Done.
  1202.  
  1203. :: JOB: Remove outdated JRE runtimes (security risk)
  1204. echo %CUR_DATE% %TIME%    Checking and removing outdated JRE installations...>> "%LOGPATH%\%LOGFILE%"
  1205. echo %CUR_DATE% %TIME%    Checking and removing outdated JRE installations...
  1206. if /i %DRY_RUN%==yes goto skip_jre_update
  1207. :: Okay, so all JRE runtimes (series 4-8) use product GUIDs, with certain numbers that increment with each new update (e.g. Update 25)
  1208. :: This makes it easy to catch ALL of them through liberal use of WMI wildcards ("_" is single character, "%" is any number of characters)
  1209. :: Additionally, JRE 6 introduced 64-bit runtimes, so in addition to the two-digit Update XX revision number, we also check for the architecture
  1210. :: type, which always equals '32' or '64'. The first wildcard is the architecture, the second is the revision/update number.
  1211.  
  1212. :: JRE 8
  1213. :: we skip JRE 8 because the JRE 8 updater automatically removes older versions, no need to do it twice
  1214.  
  1215. :: JRE 7
  1216. echo %CUR_DATE% %TIME%    JRE 7...>> "%LOGPATH%\%LOGFILE%"
  1217. echo %CUR_DATE% %TIME%    JRE 7...
  1218. %WMIC% product where "IdentifyingNumber like '{26A24AE4-039D-4CA4-87B4-2F___170__FF}'" call uninstall /nointeractive >> "%LOGPATH%\%LOGFILE%"
  1219.  
  1220. :: JRE 6
  1221. echo %CUR_DATE% %TIME%    JRE 6...>> "%LOGPATH%\%LOGFILE%"
  1222. echo %CUR_DATE% %TIME%    JRE 6...
  1223. :: 1st line is for updates 23-xx, after 64-bit runtimes were introduced.
  1224. :: 2nd line is for updates 1-22, before Oracle released 64-bit JRE 6 runtimes
  1225. %WMIC% product where "IdentifyingNumber like '{26A24AE4-039D-4CA4-87B4-2F8__160__FF}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
  1226. %WMIC% product where "IdentifyingNumber like '{3248F0A8-6813-11D6-A77B-00B0D0160__0}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
  1227.  
  1228. :: JRE 5
  1229. echo %CUR_DATE% %TIME%    JRE 5...>> "%LOGPATH%\%LOGFILE%"
  1230. echo %CUR_DATE% %TIME%    JRE 5...
  1231. %WMIC% product where "IdentifyingNumber like '{3248F0A8-6813-11D6-A77B-00B0D0150__0}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
  1232.  
  1233. :: JRE 4
  1234. echo %CUR_DATE% %TIME%    JRE 4...>> "%LOGPATH%\%LOGFILE%"
  1235. echo %CUR_DATE% %TIME%    JRE 4...
  1236. %WMIC% product where "IdentifyingNumber like '{7148F0A8-6813-11D6-A77B-00B0D0142__0}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
  1237.  
  1238. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1239. echo %CUR_DATE% %TIME%    Done.
  1240.  
  1241. :: JOB: Java Runtime 8
  1242. echo %CUR_DATE% %TIME%    Launch job 'Update Java Runtime Environment'...>> "%LOGPATH%\%LOGFILE%"
  1243. echo %CUR_DATE% %TIME%    Launch job 'Update Java Runtime Environment'...
  1244.  
  1245. :: Check if we're on 32-bit Windows and run the appropriate installer
  1246. if /i '%PROCESSOR_ARCHITECTURE%'=='x86' (
  1247.     echo %CUR_DATE% %TIME%    x86 architecture detected, installing x86 version...>> "%LOGPATH%\%LOGFILE%"
  1248.     echo %CUR_DATE% %TIME%    x86 architecture detected, installing x86 version...
  1249.     pushd java\jre\8\x86
  1250.     setlocal
  1251.     call "jre-8-i586.bat"
  1252.     endlocal
  1253.     popd
  1254. ) else (
  1255.     echo %CUR_DATE% %TIME%    x64 architecture detected, installing x64 version...>> "%LOGPATH%\%LOGFILE%"
  1256.     echo %CUR_DATE% %TIME%    x64 architecture detected, installing x64 version...
  1257.     pushd java\jre\8\x64
  1258.     setlocal
  1259.     call "jre-8-x64.bat"
  1260.     endlocal
  1261.     popd
  1262.     )
  1263.  
  1264. :skip_jre_update
  1265. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1266. echo %CUR_DATE% %TIME%    Done.
  1267.  
  1268.  
  1269. :: JOB: Skip point for if -sp (skip patches) flag was used
  1270. :skip_patches
  1271.  
  1272.  
  1273. :: JOB: Windows updates
  1274. echo %CUR_DATE% %TIME%    Launch job 'Install Windows updates'...>> "%LOGPATH%\%LOGFILE%"
  1275. echo %CUR_DATE% %TIME%    Launch job 'Install Windows updates'...
  1276. pushd windows_updates
  1277. if /i %DRY_RUN%==no wuauclt /detectnow /updatenow
  1278. popd
  1279. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1280. echo %CUR_DATE% %TIME%    Done.
  1281.  
  1282.  
  1283. :: JOB: Rebuild Windows Update base (deflates the SxS store; note that any Windows Updates installed prior to this point will become uninstallable)
  1284. :: Windows 8/2012 and up only
  1285. echo %CUR_DATE% %TIME%    Launch job 'DISM base reset'...>> "%LOGPATH%\%LOGFILE%"
  1286. echo %CUR_DATE% %TIME%    Launch job 'DISM base reset'...
  1287. pushd dism_base_reset
  1288. if /i %DRY_RUN%==no (
  1289.     if /i not "%WIN_VER:~0,9%"=="Microsoft" (
  1290.         if /i not "%WIN_VER:~0,11%"=="Windows V" (
  1291.             Dism /online /Cleanup-Image /StartComponentCleanup /ResetBase /Logpath:"%LOGPATH%\tron_dism_base_reset.log"
  1292.             type "%LOGPATH%\tron_dism_base_reset.log" >> "%LOGPATH%\%LOGFILE%"
  1293.             )
  1294.         )
  1295.     )
  1296. popd
  1297. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1298. echo %CUR_DATE% %TIME%    Done.
  1299.  
  1300. popd
  1301. echo %CUR_DATE% %TIME%   Completed stage_4_patch jobs.>> "%LOGPATH%\%LOGFILE%"
  1302. echo %CUR_DATE% %TIME%   Completed stage_4_patch jobs.
  1303.  
  1304.  
  1305. :::::::::::::::::::::::
  1306. :: STAGE 5: Optimize ::
  1307. :::::::::::::::::::::::
  1308. :stage_5_optimize
  1309. title TRON v%SCRIPT_VERSION% [stage_5_optimize]
  1310. pushd resources\stage_5_optimize
  1311. echo %CUR_DATE% %TIME%   Launch stage_5_optimize jobs...>> "%LOGPATH%\%LOGFILE%"
  1312. echo %CUR_DATE% %TIME%   Launch stage_5_optimize jobs...
  1313.  
  1314. :: JOB: chkdsk the system drive
  1315. echo %CUR_DATE% %TIME%    Launch job 'chkdsk'...>> "%LOGPATH%\%LOGFILE%"
  1316. echo %CUR_DATE% %TIME%    Launch job 'chkdsk'...
  1317. pushd chkdsk
  1318. echo %CUR_DATE% %TIME%    Checking %SystemDrive% for errors...>> "%LOGPATH%\%LOGFILE%"
  1319. echo %CUR_DATE% %TIME%    Checking %SystemDrive% for errors...
  1320.  
  1321. :: Run a read-only scan and look for errors. Schedule a scan at next reboot if errors found
  1322. if /i %DRY_RUN%==no %SystemRoot%\System32\chkdsk.exe %SystemDrive%
  1323. if /i not %ERRORLEVEL%==0 (
  1324.     echo %CUR_DATE% %TIME% !  Errors found on %SystemDrive%. Scheduling full chkdsk at next reboot.>> "%LOGPATH%\%LOGFILE%"
  1325.     echo %CUR_DATE% %TIME% !  Errors found on %SystemDrive%. Scheduling full chkdsk at next reboot.
  1326.     if /i %DRY_RUN%==no fsutil dirty set %SystemDrive%
  1327. ) else (
  1328.     echo %CUR_DATE% %TIME%    No errors found on %SystemDrive%. Skipping full chkdsk at next reboot.>> "%LOGPATH%\%LOGFILE%"
  1329.     echo %CUR_DATE% %TIME%    No errors found on %SystemDrive%. Skipping full chkdsk at next reboot.
  1330.     )
  1331.    
  1332. popd
  1333. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1334. echo %CUR_DATE% %TIME%    Done.
  1335.  
  1336.  
  1337. :: Check if we are supposed to run a defrag before doing this section
  1338. if "%SKIP_DEFRAG%"=="yes" (
  1339.     echo %CUR_DATE% %TIME%    SKIP_DEFRAG set to "%SKIP_DEFRAG%". Skipping defrag.>> "%LOGPATH%\%LOGFILE%"
  1340.     echo %CUR_DATE% %TIME%    SKIP_DEFRAG set to "%SKIP_DEFRAG%". Skipping defrag.
  1341.     popd
  1342.     goto :wrap-up
  1343.     )
  1344.  
  1345. :: Check if a Solid State hard drive was detected before doing this section
  1346. if "%SSD_DETECTED%"=="yes" (
  1347.     echo %CUR_DATE% %TIME%    Solid State hard drive detected. Skipping job 'Defrag %SystemDrive%'.>> "%LOGPATH%\%LOGFILE%"
  1348.     echo %CUR_DATE% %TIME%    Solid State hard drive detected. Skipping job 'Defrag %SystemDrive%'.
  1349.     popd
  1350.     goto :wrap-up
  1351.     )
  1352.  
  1353. :: JOB: Defrag the system drive
  1354. if "%SSD_DETECTED%"=="no" (
  1355.     echo %CUR_DATE% %TIME%    Launch job 'Defrag %SystemDrive%'...>> "%LOGPATH%\%LOGFILE%"
  1356.     echo %CUR_DATE% %TIME%    Launch job 'Defrag %SystemDrive%'...
  1357.     pushd defrag
  1358.     if /i %DRY_RUN%==no defraggler.exe %SystemDrive%
  1359.     popd
  1360.     echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1361.     echo %CUR_DATE% %TIME%    Done.
  1362.     )
  1363.  
  1364. popd
  1365. echo %CUR_DATE% %TIME%   Completed stage_5_optimize jobs.>> "%LOGPATH%\%LOGFILE%"
  1366. echo %CUR_DATE% %TIME%   Completed stage_5_optimize jobs.
  1367.  
  1368.  
  1369. :::::::::::::
  1370. :: Wrap-up ::
  1371. :::::::::::::
  1372. :wrap-up
  1373. echo %CUR_DATE% %TIME%   Wrapping up...>> "%LOGPATH%\%LOGFILE%"
  1374. echo %CUR_DATE% %TIME%   Wrapping up...
  1375.  
  1376. :: If selected, import the original power settings, re-activate them, and delete the backup
  1377. :: Otherwise, just reset the power settings back to their defaults
  1378. if "%PRESERVE_POWER_SCHEME%"=="yes" (
  1379.     echo %CUR_DATE% %TIME%    Restoring power settings to previous values...>> "%LOGPATH%\%LOGFILE%"
  1380.     echo %CUR_DATE% %TIME%    Restoring power settings to previous values...
  1381.     :: Check for Windows XP
  1382.     if "%WIN_VER%"=="Microsoft Windows XP" (
  1383.         if /i %DRY_RUN%==no powercfg /import "%POWER_SCHEME%" /file %LOGPATH%\tron_power_config_backup.pow
  1384.         if /i %DRY_RUN%==no powercfg /setactive "%POWER_SCHEME%"
  1385.     )
  1386.     :: Check for Windows Server 2003
  1387.     if "%WIN_VER%"=="Microsoft Windows Server 2003" (
  1388.             if /i %DRY_RUN%==no powercfg /import "%POWER_SCHEME%" /file %LOGPATH%\tron_power_config_backup.pow
  1389.             if /i %DRY_RUN%==no powercfg /setactive "%POWER_SCHEME%"
  1390.     ) else (
  1391.         REM if we made it this far we're not on XP or 2k3 and we can run the standard commands
  1392.         if /i %DRY_RUN%==no powercfg /import %LOGPATH%\tron_power_config_backup.pow %POWER_SCHEME% 2>NUL
  1393.         if /i %DRY_RUN%==no powercfg /setactive %POWER_SCHEME%
  1394.     )
  1395.     :: cleanup
  1396.     del %LOGPATH%\tron_power_config_backup.pow 2>NUL
  1397. ) else (
  1398.     echo %CUR_DATE% %TIME%    Resetting Windows power settings to defaults...>> "%LOGPATH%\%LOGFILE%"
  1399.     echo %CUR_DATE% %TIME%    Resetting Windows power settings to defaults...
  1400.     :: Check for Windows XP
  1401.     if "%WIN_VER%"=="Microsoft Windows XP" (
  1402.         if /i %DRY_RUN%==no powercfg /RestoreDefaultPolicies
  1403.     )
  1404.     :: check for Windows Server 2003
  1405.     if "%WIN_VER%"=="Microsoft Windows Server 2003" (
  1406.         if /i %DRY_RUN%==no powercfg /RestoreDefaultPolicies
  1407.     ) else (
  1408.         REM if we made it this far we're not on XP or 2k3 and we can run the standard commands
  1409.         if /i %DRY_RUN%==no powercfg -restoredefaultschemes
  1410.     )
  1411. )
  1412.  
  1413. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1414. echo %CUR_DATE% %TIME%    Done.
  1415.  
  1416. :: Collect misc logs and deposit them in the log folder. Thanks to /u/swtester
  1417. echo %CUR_DATE% %TIME%    Collecting misc logs and dumping them in "%LOGPATH%"...>> "%LOGPATH%\%LOGFILE%"
  1418. echo %CUR_DATE% %TIME%    Collecting misc logs and dumping them in "%LOGPATH%"
  1419. if exist "%ProgramData%\Sophos\Sophos Virus Removal Tool\Logs" copy /Y "%ProgramData%\Sophos\Sophos Virus Removal Tool\Logs\*.l*" "%LOGPATH%" >NUL
  1420. if exist "%ProgramData%\Malwarebytes\Malwarebytes Anti-Malware\Logs" copy /Y "%ProgramData%\Malwarebytes\Malwarebytes Anti-Malware\Logs\*.xml" "%LOGPATH%" >NUL
  1421. echo %CUR_DATE% %TIME%    Done.>> "%LOGPATH%\%LOGFILE%"
  1422. echo %CUR_DATE% %TIME%    Done.
  1423.    
  1424. title TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%) [DONE]
  1425.  
  1426. echo %CUR_DATE% %TIME%   DONE. Use tools in resources\stage_7_manual_tools if further cleaning is required.>> "%LOGPATH%\%LOGFILE%"
  1427. echo %CUR_DATE% %TIME%   DONE. Use tools in resources\stage_7_manual_tools if further cleaning is required.
  1428.  
  1429. :: Check if auto-reboot was requested
  1430. if "%AUTO_REBOOT_DELAY%"=="0" (
  1431.     echo %CUR_DATE% %TIME% ! Auto-reboot disabled. Recommend rebooting as soon as possible.>> "%LOGPATH%\%LOGFILE%"
  1432.     echo %CUR_DATE% %TIME% ! Auto-reboot disabled. Recommend rebooting as soon as possible.
  1433. ) else (
  1434.     echo %CUR_DATE% %TIME% ! Auto-reboot selected. Rebooting in %AUTO_REBOOT_DELAY% seconds.>> "%LOGPATH%\%LOGFILE%"
  1435.     echo %CUR_DATE% %TIME% ! Auto-reboot selected. Rebooting in %AUTO_REBOOT_DELAY% seconds.
  1436.     )
  1437.  
  1438. :: Check if shutdown was requested
  1439. if /i %AUTO_SHUTDOWN%==yes (
  1440.     echo %CUR_DATE% %TIME% ! Auto-shutdown selected. Shutting down in %AUTO_REBOOT_DELAY% seconds.>> "%LOGPATH%\%LOGFILE%"
  1441.     echo %CUR_DATE% %TIME% ! Auto-shutdown selected. Shutting down in %AUTO_REBOOT_DELAY% seconds.
  1442. )
  1443.  
  1444. :: Check if self-destruct was set
  1445. if /i %SELF_DESTRUCT%==yes (
  1446.     echo %CUR_DATE% %TIME% ! Self-destruct selected. De-rezzing self. Goodbye...>> "%LOGPATH%\%LOGFILE%"
  1447.     echo %CUR_DATE% %TIME% ! Self-destruct selected. De-rezzing self. Goodbye...
  1448. )
  1449.  
  1450. :: Calculate saved disk space
  1451. for /F "tokens=2 delims=:" %%a in ('fsutil volume diskfree %SystemDrive% ^| find /i "avail free"') do set bytes=%%a
  1452. :: GB version
  1453. ::set /A FREE_SPACE_BEFORE=%bytes:~0,-3%/1024*1000/1024/1024
  1454. :: MB version
  1455. set /A FREE_SPACE_AFTER=%bytes:~0,-3%/1024*1000/1024
  1456. set /a FREE_SPACE_SAVED=%FREE_SPACE_AFTER% - %FREE_SPACE_BEFORE%
  1457.  
  1458.  
  1459. :: Email report if it was requested
  1460. :: This line needed for param5 (/p5)
  1461. set ARGUMENTS='%*'
  1462. setlocal enabledelayedexpansion
  1463. if /i %EMAIL_REPORT%==yes (
  1464.     echo %CUR_DATE% %TIME%   Email report requested. Sending report now...>> "%LOGPATH%\%LOGFILE%"
  1465.     echo %CUR_DATE% %TIME%   Email report requested. Sending report now...
  1466.     pushd resources\stage_6_wrap-up\email_report
  1467.     SwithMail.exe /s /x "SwithMailSettings.xml" /a %LOGPATH%\%LOGFILE% /p1 "Tron v%SCRIPT_VERSION% (%SCRIPT_DATE%) executed as %USERDOMAIN%\%USERNAME%" /p2
  1468.  
  1469. "%LOGPATH%\%LOGFILE%" /p3 "%SAFE_MODE% %SAFEBOOT_OPTION%" /p4 "%FREE_SPACE_BEFORE%/%FREE_SPACE_AFTER%/%FREE_SPACE_SAVED%" /p5 "%ARGUMENTS%"
  1470.     if %ERRORLEVEL%==0 (
  1471.         echo %CUR_DATE% %TIME%   Done.>> "%LOGPATH%\%LOGFILE%"
  1472.         echo %CUR_DATE% %TIME%   Done.
  1473.         ) else (
  1474.         echo %CUR_DATE% %TIME% ! Something went wrong, email may not have gone out. Check your settings.>> "%LOGPATH%\%LOGFILE%"
  1475.         echo %CUR_DATE% %TIME% ! Something went wrong, email may not have gone out. Check your settings.
  1476.     )
  1477. )
  1478. endlocal disabledelayedexpansion
  1479.  
  1480.  
  1481.  
  1482. :: Display and log the job summary
  1483. echo ------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%
  1484. echo -------------------------------------------------------------------------------
  1485. echo  %CUR_DATE% %TIME%  TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%) complete>> %LOGPATH%\%LOGFILE%
  1486. echo  %CUR_DATE% %TIME%  TRON v%SCRIPT_VERSION% (%SCRIPT_DATE%) complete
  1487. echo                          Executed as "%USERDOMAIN%\%USERNAME%" on %COMPUTERNAME%>> %LOGPATH%\%LOGFILE%
  1488. echo                          Executed as "%USERDOMAIN%\%USERNAME%" on %COMPUTERNAME%
  1489. echo                          Logfile: %LOGPATH%\%LOGFILE%>> %LOGPATH%\%LOGFILE%
  1490. echo                          Logfile: %LOGPATH%\%LOGFILE%
  1491. echo                          Command-line flags: %*>> %LOGPATH%\%LOGFILE%
  1492. echo                          Command-line flags: %*
  1493. echo                          Safe Mode: %SAFE_MODE% %SAFEBOOT_OPTION%>> %LOGPATH%\%LOGFILE%
  1494. echo                          Safe Mode: %SAFE_MODE% %SAFEBOOT_OPTION%
  1495. echo                          Free space before Tron run: %FREE_SPACE_BEFORE% MB>> %LOGPATH%\%LOGFILE%
  1496. echo                          Free space before Tron run: %FREE_SPACE_BEFORE% MB
  1497. echo                          Free space after Tron run:  %FREE_SPACE_AFTER% MB>> %LOGPATH%\%LOGFILE%
  1498. echo                          Free space after Tron run:  %FREE_SPACE_AFTER% MB
  1499. echo                          Disk space reclaimed:       %FREE_SPACE_SAVED% MB>> %LOGPATH%\%LOGFILE%
  1500. echo                          Disk space reclaimed:       %FREE_SPACE_SAVED% MB
  1501. echo ------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%
  1502. echo -------------------------------------------------------------------------------
  1503.  
  1504.  
  1505. :: Skip all this if we're doing a dry run
  1506. if /i %DRY_RUN%==yes goto end_and_skip_shutdown
  1507.  
  1508. :: Perform reboot if requested
  1509. if /i not "%AUTO_REBOOT_DELAY%"=="0" shutdown -r -f -t %AUTO_REBOOT_DELAY% -c "Rebooting in %AUTO_REBOOT_DELAY% seconds to finish cleanup."
  1510.  
  1511. :: Perform shutdown if requested
  1512. if /i %AUTO_SHUTDOWN%==yes shutdown -f -t %AUTO_REBOOT_DELAY% -s
  1513.  
  1514. :: De-rez self if requested
  1515. set CWD=%CD%
  1516. if /i %SELF_DESTRUCT%==yes (
  1517.     %SystemDrive%
  1518.     cd \
  1519.     rmdir /s /q %CWD%
  1520.     )
  1521.  
  1522. :end_and_skip_shutdown
  1523. pause
  1524. color
Advertisement
Add Comment
Please, Sign In to add comment