Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- ::This script was made by /u/EverChillingLucifer
- ::The purpose of it is to create a time-stamped log file in the event of a program crash or other such problems.
- ::I will explain each line simply.
- ::Both of the below lines will create a log file in the designated locations.
- ::If the folder does not exist, it will create it and then perform the commands.
- ::If it does exist, it ignores the creation command and executes the original log commands.
- if exist C:\Support\Logs goto :exists
- if not exist C:\Support\Logs goto :notexist
- :exists
- goto :createlogs
- :notexist
- goto :makefolder
- :makefolder
- echo "Creating folder, please wait..."
- mkdir C:\Support\Logs
- goto :createlogs
- ::Creates the logs with these commands.
- ::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.
- :createlogs
- tasklist > C:\Support\Logs\processes_list.log
- tasklist/svc > C:\Support\Logs\services_list.log
- WEVTUtil query-events System /count:50 /rd:true /format:text > C:\Support\Logs\event_log_System.log
- WEVTUtil query-events Application /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Application.log
- WEVTUtil query-events Security /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Security.log
- WEVTUtil query-events Setup /count:50 /rd:true /format:text > C:\Support\Logs\event_log_Setup.log
- goto :dandt
- ::This adds the date and time to the files created.
- ::I opted to keep the original file names the exact same since they would be separated by the date and time either way.
- ::This allows for less lines of code and less to worry about in the long run.
- :dandt
- 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"
- 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"
- 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"
- 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"
- 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"
- 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"
- goto :moveandrename
- ::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.
- :moveandrename
- cls
- mkdir C:\Support\Logs\template
- move C:\Support\Logs\*.log C:\Support\Logs\template
- ren C:\Support\Logs\template "logs_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%"
- goto :complete
- ::Just so the user knows if it worked.
- :complete
- cls
- echo "The process has complete, the folder will open now...
- pause
- goto :openlogs
- ::Then it simply opens the folder through explorer.exe and terminates the batch file.
- :openlogs
- %SystemRoot%\explorer.exe "C:\Support\Logs"
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement