bearbear12345

MSE VirusScan.bat by bearbear12345

May 25th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 10.90 KB | None | 0 0
  1. @echo off
  2. rem Microsoft Security Essentials Scan Script
  3. rem   Script by Andrew Wong (bearbear12345)
  4. rem   Email: [email protected]
  5. rem   Skype: aw929292929683244
  6.  
  7. ::::::::::::::::::::::::::::::::::::::::CONFIGURATION::::::::::::::::::::::::::::::::::::::::
  8.  
  9.  
  10. :: Provide the path to your Microsoft Security Essentials Directory
  11. :: Don't use quotes
  12. rem Default: C:\Program Files\Microsoft Security Client
  13. set SecurityEssentialsDirectory=C:\Program Files\Microsoft Security Client
  14.  
  15.  
  16. :: Temporary File Locations
  17. :: Don't use quotes
  18. rem Default: %APPDATA%
  19. set tempdir=%APPDATA%
  20.  
  21.  
  22. :: SCAN TYPE
  23. ::   Types:
  24. ::     0 - Default, according to your configuration
  25. ::     1 - Quick Scan
  26. ::     2 - Full System Scan
  27. ::     3 - Custom File/Directory Scan
  28. rem Default: 2
  29. set scantype=2
  30.  
  31. ::     Below Only Applies If scantype Is 3 (Custom File/Directory Scan)
  32. :: Don't use quotes
  33. rem EG: C:\Users\User\Downloads
  34. rem EG: C:\Users\User\Downloads\Application.exe
  35. set filedir=
  36.  
  37. :: Time (In Seconds) to wait before shutdown\
  38. :: -1 will not turn off the computer.
  39. :: 0 will turn off the computer instantly.
  40. rem Note: You can cancel the shutdown timer by running `shutdown -a`
  41. rem Default: 180 (3 minutes)
  42. set timer=180
  43.  
  44. ::::::::::::::::::::::::::::::::::::::END CONFIGURATION::::::::::::::::::::::::::::::::::::::
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. :: DO NOT EDIT BELOW
  93. :: WELL YOU CAN, IF YOU WANT IT TO BREAK!!
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. rem Clears The Screen
  105. cls
  106. rem Set background color to Black, and forgeground to Light Green
  107. color 0A
  108. rem Gives the batch script a title
  109. title Microsoft Security Essentials Scan Script - Andrew Wong
  110.  
  111. ::Configuration Field Checks
  112. rem Checks if SecurityEssentialsDirectory is an actual path
  113. if not exist "%SecurityEssentialsDirectory%" goto not_installed
  114. rem Checks if SecurityEssentialsDirectory contains MpCmdRun.exe - Not exactly effective, but most people wouldn't troll around with virus protection :D
  115. if not exist "%SecurityEssentialsDirectory%\MpCmdRun.exe" goto dir_error
  116. rem Checks if the tempdir is defined
  117. if not defined tempdir goto tempdir_not_defined
  118. rem Checks if tempdir is existent
  119. if not exist %tempdir% goto tempdir_not_exist
  120. rem Checks if tempdir is writable by the user
  121. bearbear12345_was_here_xD >"%tempdir%\.tempfilecheck" 2>nul
  122. if not exist "%tempdir%\.tempfilecheck" goto tempdir_no_write
  123. del "%tempdir%\.tempfilecheck"
  124. rem Checks if scantype is defined
  125. if not defined scantype goto scantype_not_defined
  126. rem Checks for a good scantype value (0,1,2,3)
  127. set scantotal=0
  128. set increasescantotal=set /a scantotal=%scantotal%+1
  129. if %scantype%==0 %increasescantotal%
  130. if %scantype%==1 %increasescantotal%
  131. if %scantype%==2 %increasescantotal%
  132. if %scantype%==3 %increasescantotal%
  133. if %scantotal%==0 goto bad_scantype
  134. rem Checks if filedir is defined when scantype is 3 (Custom File/Directory Scan)
  135. if %scantype%==3 if not defined filedir goto filedir_not_defined
  136. rem Checks if filedir is an actual path or directory
  137. if %scantype%==3 if not exist "%filedir%" goto filedir_not_found
  138. rem Checks for a timer value
  139. if not defined timer goto aint_got_time_for_dat
  140. ::END Configuration Field Checks
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. ::DATE AND TIME
  152. rem Gets output of date /T and stores it in %tempdir%\.tempdate
  153. date /T > %tempdir%\.tempdate
  154. rem Sets variable date to the contents of %tempdir%\.tempdate
  155. set /p date= < %tempdir%\.tempdate
  156. rem Deletes %tempdir%\.tempdate
  157. del %tempdir%\.tempdate
  158.  
  159. rem Gets output of time /T and stores it in %tempdir%\.temptime
  160. time /T > %tempdir%\.temptime
  161. rem Sets variable time to the contents of %tempdir%\.temptime
  162. set /p time= < %tempdir%\.temptime
  163. rem Deletes %tempdir%\.temptime
  164. del %tempdir%\.temptime
  165. ::END DATE AND TIME
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. ::INITITATION
  177. rem Prints out initial date and time of scan
  178. echo Automated Virus Scan Started: %date%%time%
  179. rem New Line
  180. echo.
  181. rem Prints out configured MSE directory
  182. echo Security Essentials Directory: %SecurityEssentialsDirectory%
  183. echo.
  184. rem Changes Directory To %SecurityEssentialsDirectory%
  185. cd /D "%SecurityEssentialsDirectory%"
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. ::VIRUS DEFINITIONS
  197. rem Prints "Updating Virus Definitions..."
  198. echo Updating Virus Definitions...
  199. rem Updates Virus Definitions, or what they call signatures.
  200. MpCmdRun.exe -signatureupdate
  201. rem New line
  202. echo.
  203. ::END VIRUS DEFINITIONS
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214. ::Scan type check
  215. if %scantype%==0 goto scan_0
  216. if %scantype%==1 goto scan_1
  217. if %scantype%==2 goto scan_2
  218. if %scantype%==3 goto scan_3
  219. ::End Scan type check
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230. ::SCAN COMPONENT
  231. :scan_0
  232. rem Virus Scan on Default
  233. echo Starting Virus Scan (Mode: Default)
  234. rem Actually Starts The Scan
  235. MpCmdRun.exe -scan -scantype 0
  236. goto continue
  237. :scan_1
  238. rem Virus Scan on Quick Scan
  239. echo Starting Virus Scan (Mode: Quick Scan)
  240. rem Actually Starts The Scan
  241. MpCmdRun.exe -scan -scantype 1
  242. goto continue
  243. :scan_2
  244. rem Virus Scan on Full Scan
  245. echo Starting Virus Scan (Mode: Full Scan)
  246. rem Actually Starts The Scan
  247. MpCmdRun.exe -scan -scantype 2
  248. goto continue
  249. :scan_3
  250. rem Virus Scan on Custom Scan
  251. echo Starting Virus Scan (Mode: Custom Scan)
  252. echo File/Directory to scan: %filedir%
  253. rem Actually Starts The Scan
  254. MpCmdRun.exe -scan -scantype 3 -file "%filedir%"
  255. goto continue
  256.  
  257. :continue
  258. rem Checks errorlevel of scan, 0 means success
  259. if %ERRORLEVEL%==0 (
  260. echo Scan Completed! Your Computer Is Clean!
  261. ) else (
  262. rem This is called when there is an error in the scan
  263. rem EG: Virus can't be removed
  264. echo Scan Completed! Problems Have Been Detected During Scan!
  265. echo Please check the History for more information!
  266. )
  267.  
  268. goto end
  269. ::END SCAN COMPONENT
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. ::ERRORS
  281. :not_installed
  282. rem Called when %SecurityEssentialsDirectory% is not existent
  283. echo Microsoft Security Essentials is not installed!
  284. echo For this script to work, please install it.
  285. echo.
  286. echo Website Link:
  287. echo http://windows.microsoft.com/en-au/windows/security-essentials-download
  288. echo.
  289. echo The website will be opened in 30 seconds.
  290. echo If you would like to cancel, either close the window, or press Ctrl+C (followed by a 'y')
  291. timeout /T 30 /nobreak
  292. if %ERRORLEVEL%==0 (
  293. start http://windows.microsoft.com/en-au/windows/security-essentials-download
  294. echo Webpage opened!
  295. echo Please install Microsoft Security Essentials, and restart this script to continue
  296. echo Press a key to exit!
  297. pause > nul
  298. goto :EOF
  299. )
  300.  
  301. :dir_error
  302. rem Called when %SecurityEssentialsDirectory% is existent, but required files are not found
  303. echo The folder %SecurityEssentialsDirectory% exists, but files are missing!
  304. echo Please re-install or repair your copy of Microsoft Security Essentials!
  305. echo.
  306. echo Press a key to exit!
  307. pause > nul
  308. goto :EOF
  309.  
  310. :tempdir_not_defined
  311. rem Called when the tempdir field is empty
  312. echo Please enter a directory path into the tempdir field of this script!
  313. echo.
  314. echo Press a key to exit!
  315. pause > nul
  316. goto :EOF
  317.  
  318. :tempdir_not_exist
  319. rem Called when the tempdir field is not existent
  320. echo The path %tempdir% has been entered into the tempdir field, but it is not existent!
  321. echo Please input an existent directory!
  322. echo.
  323. echo Press a key to exit!
  324. pause > nul
  325. goto :EOF
  326.  
  327. :tempdir_no_write
  328. rem Called when the tempdir field is existent, but cannot be written to
  329. echo You do not have access to write files into %tempdir%!
  330. echo Please change the tempdir field to a writable path!
  331. echo.
  332. echo Press a key to exit!
  333. pause > nul
  334. goto :EOF
  335.  
  336. :scantype_not_defined
  337. rem Called when the scantype field is empty
  338. echo Please input a scan type!
  339. echo.
  340. echo Types:
  341. echo   0 - Default, according to your configuration
  342. echo   1 - Quick Scan
  343. echo   2 - Full System Scan
  344. echo   3 - Custom File/Directory Scan (And enter something in the filedir field)
  345. echo.
  346. echo Press a key to exit!
  347. pause > nul
  348. goto :EOF
  349.  
  350. :bad_scantype
  351. rem Called when the scantype field is an incorrect value of 0, 1, 2 or 3
  352. echo You have entered a bad scan type!
  353. echo Please change the scantype to a value below
  354. echo.
  355. echo Types:
  356. echo   0 - Default, according to your configuration
  357. echo   1 - Quick Scan
  358. echo   2 - Full System Scan
  359. echo   3 - Custom File/Directory Scan (And enter something in the filedir field)
  360. echo.
  361. echo Press a key to exit!
  362. pause > nul
  363. goto :EOF
  364.  
  365. :filedir_not_defined
  366. rem Called when the scantype field is 3, and filedir field is empty
  367. echo Please enter a file or directory path into the filedir field of this script!
  368. echo.
  369. echo Press a key to exit!
  370. pause > nul
  371. goto :EOF
  372.  
  373. :filedir_not_found
  374. rem Called when the scantype field is 3, and filedir field is not existent
  375. echo The file/directory path %filedir% has been entered into the filedir field, but it is not existent!
  376. echo Please input an existent file/directory path!
  377. echo.
  378. echo Press a key to exit!
  379. pause > nul
  380. goto :EOF
  381. :aint_got_time_for_dat
  382. rem Get it? I mean Git it?
  383. echo Please enter a value into the timer field!
  384. echo Value is in seconds. From -1 to 99999
  385. echo -1 will not turn off the computer.
  386. echo 0 will turn off the computer instantly.
  387. echo.
  388. echo Press a key to exit!
  389. pause > nul
  390. goto :EOF
  391. ::END ERRORS
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. :end
  403. ::Creates Startup Script Relaying Information
  404.  
  405. rem Checks if timer is -1, which would not turn off the computer, hence no startup script
  406. if %timer%==-1 (
  407. echo Press a key to exit!
  408. pause > nul
  409. goto :EOF
  410. )
  411.  
  412. rem Checks OS is Windows XP or later, and defines file location of securityscan_result.vbs
  413. if exist "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" (
  414. ::Windows Vista/7/8
  415. set securityscan_result="%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\securityscan_result.vbs"
  416. ) else (
  417. rem Fallback to XP directory
  418. ::Windows XP and below
  419. set securityscan_result="%userprofile%\Start Menu\Programs\Startup\securityscan_result.vbs"
  420. )
  421. rem Creates result information
  422. if %errorlevel%==0 (
  423. set result=Your computer is protected!
  424. set resultcode=64
  425. ) else (
  426. set result=There were problems detected during scan, please rectify the issue!
  427. set resultcode=48
  428. )
  429. rem Writes script to securityscan_result.vbs
  430. echo CreateObject("Scripting.FileSystemObject").DeleteFile(Wscript.ScriptFullName) > %securityscan_result%
  431. rem setlocal enableDelayedExpansion to put a variable into another one?
  432. setlocal enableDelayedExpansion
  433. set line2=msgbox "The Virus Scan Performed At %date%%time% was completed." + vbnewline + "%result%", %resultcode%
  434. echo !line2! >> %securityscan_result%
  435. endlocal
  436. echo Startup Script Created!
  437.  
  438. rem Shuts computer down after (%timer% field) seconds
  439. shutdown -s -t %timer% -c "Notice: Microsoft Security Essentials Has Finished Scanning And Will Turn Of In 3 Minutes."
  440. echo To abort this, please run 'shutdown -a'
  441. goto :EOF
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541. Script by Andrew Wong (bearbear12345)
  542. Email: andrew.j.wong@outlook.com
  543. Skype: aw929292929683244
Advertisement
Add Comment
Please, Sign In to add comment