Advertisement
Guest User

Untitled

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