Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- set /p "directory=Results directory: "
- if exist "%directory%" (
- echo %computername% >"%directory%\comp-name.txt"
- net time \\%computername% >"%directory%\start-time.txt"
- net user >"%directory%\users.txt"
- whoami >"%directory%\whoami.txt"
- tasklist >"%directory%\tasklist.txt"
- echo Program complete
- ) else (
- echo Output directory not found
- )
- REM ----------------------------------------------------------------------------
- REM EXPLANATIONS
- REM ----------------------------------------------------------------------------
- REM Line 01: While having echo set to On is good for debugging, you can turn it
- REM off once the script is working. Also, capitalization of commands
- REM should be consistent throughout the script.
- REM Line 02: /p is needed for getting user input, and the opening double quote
- REM ideally goes to the left of the variable name for consistency with
- REM regular set commands.
- REM Line 03: The `not` is unnecessary, as the first code block should be running
- REM if the directory DOES exist. Also, %directory% should have quotes
- REM around it in case the value contains a space.
- REM Lines 04-09: Paths to files should be wrapped in quotes in case the values
- REM contain spaces. You may also want to consider explicitly
- REM saving the files as .txt files since Windows is weird about
- REM opening files that don't have extensions.
- REM Line 05: > is used for outputting to a file, < is used for inputting from
- REM a file.
- REM Line 10: The closing parenthesis of the first code block, the else command,
- REM and the opening parenthesis of the second code block all need to
- REM be on the same line in order for the command to not throw an error.
- REM Also, refer to the Line 01 comment about consistent capitalization.
- REM ----------------------------------------------------------------------------
- REM OTHER COMMENTS
- REM ----------------------------------------------------------------------------
- REM * It is generally not a good idea to reuse command names, so renaming the
- REM whoami and tasklist output files to something else is recommended.
- REM * Code inside of parentheses ("code blocks") should be indented to
- REM distinguish it from code outside of the code blocks.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement