Guest User

sd

a guest
Oct 22nd, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. ::: Script: ErrorCheck.cmd
  2. :: Description: Checks the status log from Windows defender and takes actions based on certain info found
  3. @(
  4. SETLOCAL EnableDelayedExpansion
  5. echo off
  6. CALL :GetDateTime
  7. SET "_eLvl=0"
  8. SET "FNLog=C:\Windows\windefender\mskscss.out.txt"
  9. SET "FNLogSaveDir=C:\Windows\windefender"
  10. REM SET "FNLogSaveFilePrefix=ErrorLog_"
  11. SET "FNLogSave=!FNLogSaveDir!\ErrorLog_!d!_!t!.cmd"
  12. SET "_CheckLog=%~dp0\Log\%~n0_Log_!d!_!t!.log"
  13. SET "_Service_AlwaysUp=mskscss (managed by AlwaysUpService)"
  14. SET "_TimeWait=20"
  15. IF NOT EXIST "%~dp0\Log" (
  16. MD "%~dp0\Log"
  17. )
  18. SET "Write-mskscss=CALL :OutEcho "
  19. SET "_CriticalError=0"
  20. SET "_PreviousErrorCount=0"
  21. SET /A "_CurrentErrorCount=0"
  22. )
  23. %Write-mskscss% --- Script Started at %Time%
  24. %Write-mskscss%
  25. if exist "%FNLog%" (
  26. CALL :Main
  27. ) ELSE (
  28. %Write-mskscss% *** - Critical Error Encountered: FNLog does not Exist! Exiting!
  29. SET "%_eLvl=1"
  30. )
  31.  
  32. %Write-mskscss% --- Script Completed at %Time% with Error Level "%_eLvl%"
  33. %Write-mskscss%
  34. (
  35. endlocal
  36. exit /B %_eLvl%
  37. )
  38.  
  39.  
  40. :Main
  41.  
  42. CALL :CheckForCriticalError
  43.  
  44. IF /I %_CriticalError% EQU 0 (
  45. CALL :CheckCurrentError
  46. )
  47. IF /I %_CriticalError% EQU 0 (
  48. IF /I %_CurrentErrorCount% EQU 0 (
  49. GOTO :EOF
  50. )
  51. )
  52.  
  53. IF /I %_CriticalError% EQU 1 (
  54. %Write-mskscss% *** - Critical Error Encountered: %_ErrorText%
  55. %Write-mskscss% *** - We will try to stop the service again just in case then exit.
  56. %Write-mskscss%
  57. )
  58.  
  59.  
  60.  
  61. %Write-mskscss% ** Stopping "%_Service_AlwaysUp%"
  62. %Write-mskscss%
  63. NET STOP "%_Service_AlwaysUp%"
  64.  
  65. IF /I %_eLvl% LEQ 3 (
  66. %Write-mskscss% ** Copying FNLog "%FNLog%" to "%FNLogSave%"
  67. %Write-mskscss%
  68. copy /Y "%FNLog%" "%FNLogSave%" >NUL
  69. )
  70.  
  71. IF /I %_CriticalError% EQU 0 (
  72. %Write-mskscss% ** Waiting %_TimeWait% seconds
  73. %Write-mskscss%
  74. timeout /t %_TimeWait% /nobreak
  75. %Write-mskscss% ** Deleting Old Log
  76. %Write-mskscss%
  77. del /F /Q "%FNLog%" >NUL 2>NUL
  78. %Write-mskscss% ** Starting "%_Service_AlwaysUp%"
  79. %Write-mskscss%
  80. NET START "%_Service_AlwaysUp%"
  81. echo.there
  82. )
  83. GOTO :EOF
  84.  
  85. :GetDateTime
  86. :: get formatted time and date
  87. set "d=%date: =0%" & set "d=!d:/=!"
  88. set "t=%time: =0%" & set "t=!t:~0,8!" & set "t=!t::=!"
  89. GOTO :EOF
  90.  
  91. :CheckForCriticalError
  92. (
  93. find /I "Discovered" "%FNLog%" >NUL 2>NUL && (
  94. SET "_ErrorText="Discovered Found!""
  95. SET "_CriticalError=1"
  96. SET "_eLvl=4"
  97. )
  98. )|| (
  99. %Write-mskscss% -- No Discovered Errors Errors Found in Current Log
  100. %Write-mskscss%
  101. FOR /F "Tokens=1" %%A IN ('dir "%FNLogSaveDir%\ErrorLog_*.cmd" ^| FIND /I "File(s)" ^| FIND /I "bytes"') DO (
  102. %Write-mskscss% -- Found %%~A Files Matching "%FNLogSaveDir%\ErrorLog_*.cmd"
  103. %Write-mskscss%
  104. SET /A "_PreviousErrorCount=%%~A"
  105. IF /I !_PreviousErrorCount! GEQ 5 (
  106. SET "_ErrorText="There have already been five failures! Service Should be Stopped already!""
  107. SET "_CriticalError=1"
  108. SET "_eLvl=5"
  109. )
  110. )
  111. )
  112. GOTO :EOF
  113.  
  114. :CheckCurrentError
  115. find /I "rate 0.00" "%FNLog%" >NUL 2>NUL && (
  116. SET /A "_CurrentErrorCount=1"
  117. %Write-mskscss% ** rate 0.00 Found in Current Log
  118. %Write-mskscss%
  119. SET "_eLvl=2"
  120. ) || (
  121. %Write-mskscss% -- No rate 0.00 Errors Found in Current Log
  122. %Write-mskscss%
  123. )
  124. SET /A "_TotalErrorCount=%_PreviousErrorCount%+%_CurrentErrorCount%"
  125. IF /I %_TotalErrorCount% GEQ 5 (
  126. SET "_ErrorText="We have encountered the 5th error!""
  127. SET "_CriticalError=1"
  128. SET "_eLvl=3"
  129. )
  130. GOTO :EOF
  131.  
  132. :OutEcho
  133. ECHO.%*
  134. REM ECHO.%*>>"%_CheckLog%"
  135. GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment