Advertisement
Lunk

Under Log and Error

Aug 26th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.29 KB | None | 0 0
  1. @echo off
  2. ::This script was made by /u/EverChillingLucifer
  3. ::The purpose of it is to create a time-stamped log file in the event of a program crash or other such problems.
  4.  
  5. ::I will explain each line simply.
  6. ::Both of the below lines will create a log file in the designated locations.
  7. ::If the folder does not exist, it will create it and then perform the commands.
  8. ::If it does exist, it ignores the creation command and executes the original log commands.
  9. if exist C:\Support\Logs goto :exists
  10. if not exist C:\Support\Logs goto :notexist
  11.  
  12. :exists
  13. goto :createlogs
  14.  
  15. :notexist
  16. goto :makefolder
  17.  
  18. :makefolder
  19. echo "Creating folder, please wait..."
  20. mkdir C:\Support\Logs
  21. goto :createlogs
  22.  
  23.  
  24. ::Creates the logs with these commands.
  25. ::I opted to include event logs, as some problems are simply not solved with having just the process and services list open. Sometimes there is a recent crash or power outage that was ignored, and event logs should reflect that.
  26. :createlogs
  27. tasklist > C:\Support\Logs\processes_list.log
  28. tasklist/svc > C:\Support\Logs\services_list.log
  29. WEVTUtil query-events System /count:50 /rd:true /format:text > C:\Support\Logs\event_log_System.log
  30. WEVTUtil query-events Application /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Application.log
  31. WEVTUtil query-events Security /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Security.log
  32. WEVTUtil query-events Setup /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Setup.log
  33. goto :dandt
  34.  
  35. ::This adds the date and time to the files created.
  36. ::I opted to keep the original file names the exact same since they would be separated by the date and time either way.
  37. ::This allows for less lines of code and less to worry about in the long run.
  38. :dandt
  39. ren C:\Support\Logs\processes_list.log "processes_list_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  40. ren C:\Support\Logs\services_list.log "services_list_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  41. ren C:\Support\Logs\event_log_System.log "event_log_System_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  42. ren C:\Support\Logs\event_log_Application.log "event_log_Application_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  43. ren C:\Support\Logs\event_log_Security.log "event_log_Security_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  44. ren C:\Support\Logs\event_log_Setup.log "event_log_Setup_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.log"
  45. goto :moveandrename
  46.  
  47. ::This will create the folder and then move any files with the extension ".log" into the template folder. Immediately after that, it will rename the folder and timestamp it appropriately so everything is organized.
  48. :moveandrename
  49. cls
  50. mkdir C:\Support\Logs\template
  51. move C:\Support\Logs\*.log C:\Support\Logs\template
  52. ren C:\Support\Logs\template "logs_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%"
  53. goto :complete
  54.  
  55. ::Just so the user knows if it worked.
  56. :complete
  57. cls
  58. echo "The process has complete, the folder will open now...
  59. pause
  60. goto :openlogs
  61.  
  62. ::Then it simply opens the folder through explorer.exe and terminates the batch file.
  63. :openlogs
  64. %SystemRoot%\explorer.exe "C:\Support\Logs"
  65. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement