anchor.diff:  ::                2. Safe mode is strongly recommended (though not required)
   ::                3. Called from tron.bat. If you try to run this script directly it will error out
   :: Author:        vocatus on reddit.com/r/TronScript ( vocatus.gate at gmail ) // PGP key: 0x07d1490f82a211a2
  -:: Version:       1.0.5 - Remove redundant Dism image store cleanup (move to Stage 5)
  +:: Version:       1.0.6 ! Fix numerous bugs with DISM check and repair. Due to bad ERRORLEVEL checking it would fail to trigger repairs when they were required
  +::                1.0.5 - Remove redundant Dism image store cleanup (move to Stage 5)
   ::                1.0.4 - Move Windows 7/8/8.1 telemetry removal code into separate sub-script (similar to Win10)
   ::                1.0.3 - Remove internal log function and switch to Tron's external logging function. Thanks to github:nemchik
   ::                      ! Fix incorrect file name in call to "disable_telemetry_registry_entries.reg"
  
positive.code: 
  
  :: JOB: Check Windows Image for corruptions before running SFC (Windows 8 and up)
  title Tron v%SCRIPT_VERSION% [stage_4_repair] [DISM Check]
  call functions\log.bat "%CUR_DATE% %TIME%    Launch job 'Dism Windows image check (Win8 and up)'..."
  if /i %DRY_RUN%==yes goto skip_dism_image_check
  
  :: Read WIN_VER_NUM and run the scan if we're on 8 or above
  if %WIN_VER_NUM% geq 6.2 (
  	Dism /Online /NoRestart /Cleanup-Image /ScanHealth /Logpath:"%LOGPATH%\tron_dism.log"
  	type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  	del /f /q "%LOGPATH%\tron_dism.log"
  )
  
  :: If we detect errors try to repair them
  if /i not %ERRORLEVEL%==0 (
  	title Tron v%SCRIPT_VERSION% [stage_3_disinfect] [DISM Repair]
  	if %WIN_VER_NUM% geq 6.2 (
  		call functions\log.bat "%CUR_DATE% %TIME% !  DISM: Image corruption detected. Attempting repair..."
  		:: Add /LimitAccess flag to this command to prevent connecting to Windows Update for replacement files
  		Dism /Online /NoRestart /Cleanup-Image /RestoreHealth /Logpath:"%LOGPATH%\tron_dism.log"
  		type "%LOGPATH%\tron_dism.log" >> "%LOGPATH%\%LOGFILE%"
  	) else (
  		call functions\log.bat "%CUR_DATE% %TIME%    DISM: No image corruption detected."
  	)
  )
  
  :skip_dism_image_check
  call functions\log.bat "%CUR_DATE% %TIME%    Done."
  
  
  
  :: JOB: Reset registry permissions
  
negative.code: 	if /i %DRY_RUN%==no fsutil dirty set %SystemDrive%
  ) else (
  	call functions\log.bat "%CUR_DATE% %TIME%    No errors found on %SystemDrive%. Skipping full chkdsk at next reboot."
  )
  call functions\log.bat "%CUR_DATE% %TIME%    Done."
  
  
  :: JOB: Remove Microsoft telemetry (user tracking)
  title Tron v%SCRIPT_VERSION% [stage_4_repair] [kill-telemetry]
  if /i %SKIP_TELEMETRY_REMOVAL%==yes (
  	call functions\log.bat "%CUR_DATE% %TIME% !  SKIP_TELEMETRY_REMOVAL (-str) set. Disabling instead of removing."
  	REM Only disable telemetry, don't completely purge it
  	reg import stage_4_repair\purge_windows_telemetry\disable_telemetry_registry_entries.reg >nul 2>&1
  	regedit /S stage_4_repair\purge_windows_telemetry\disable_telemetry_registry_entries.reg >nul 2>&1
  