Essential MS-DOS Batch Commands and Shutdown Parameters

Batch Commands


  • Want to play a joke on your friend using the PC?
  • Want to learn more about batch scripting?
  • Want to change codes, delete files, close applications, or create a “supposed” virus?
  • Feeling a bit clueless?

Then take a look at these few, but useful, MS-DOS commands.

Getting Started…



Basic Commands

  • DEL: Delete files. Example: del c:\address\file.exe deletes the file.
  • RD: Delete root directory. Example: rd c:\directory deletes that directory.
  • START: Start something. Example: start www.pagina.com; start c:\program\ini.exe
  • PAUSE: Pause execution.
  • EXIT: Exit the script or console.
  • TASKKILL: Kill a process. Example: taskkill /f /im nod32.exe (forcefully) or taskkill /f proceso.exe (same as tskill).
  • SET /P: Set a variable by asking a question. Example: set /p pre=Are you okay?
    To use the answer: if %pre%==2 (commands). Example: set /p pre=Are you okay? and then
    if %pre%==if goto if
    if %pre%==no goto no
  • GOTO: Jump to a label. Example: if (condition) goto if else goto no.
  • Loop: A simple way to repeat an action. Example:
    :No
    start www.google.com.ar
    goto No
    That would be an infinite loop.
  • >> <<=: Redirect output. Example: start x.exe >> ftp.txt (appends output to a file).
  • CLS: Clear the screen. Example: Pause to let the user read, then clear the screen.
  • FORMAT drive:: Format a drive. Example: format c:
  • MSG *: Display a message with a Windows message box. Example: msg * xD bye
  • ECHO: Display a message in the console. Example: echo xDDD
  • DATE: Set or display the date. Example: date x/x/x
  • TIME: Set or display the time. Example: time x:x
Well, these are the basics.

They are created in Notepad, by writing commands and saving the file with a .bat extension (e.g., mycommands.bat).

Shutdown Parameters

Let’s discuss shutdown parameters:

  • -S: Orders the computer to shut down (shutdown -s = shutdown immediately).
  • -R: Restarts the computer instead of shutting down (shutdown -r).
  • -F: Forcefully closes all applications that require authorization or confirmation.
  • -C “comment: Displays a comment in the warning screen.
  • -T seconds: Sets a timer for shutdown or restart.

Consider a practical example:
I am installing a Windows update that takes 20 minutes to install, and then I’ll have to reboot. But I don’t want to sit in front of the screen for 20 minutes. I can type the following:

shutdown -r -f -t 1800

This will restart the PC in 30 minutes (30 minutes * 60 seconds = 1800 seconds) without prompting and forcefully close all applications.

Another scenario:
I’m in a cybercafe, and I dislike the owner. I suspect they overcharged me last time, so I want to play a harmless joke that won’t damage the PC.

I can write the following:

at 17:15 shutdown -s -f -t 15 -c "Tell your landlord you've been off the computer because it's in the cocoon of my hand"

Jajajajajaja! They’ll have to see the message when they return to use the PC!

We have scheduled a task using the AT command to run at 17:15 pm. This is another command with great potential. You can, for example, schedule Counter-Strike to load or disable the antivirus (patience, we’ll cover that later).

I need to make a correction to this small manual:

The command-line task scheduler (AT) doesn’t work exactly as described above. Although the help command suggests inserting explicit commands, this doesn’t work in practice. We need to create a batch file with the code, save it to a folder, and then schedule the program to run.

In the example above, we would create a batch file with the following code:

shutdown -s -f -t 15 -c "Tell your landlord you've been off the computer, say it's in the cocoon of my hand"

We’ll give it an inconspicuous name and save it in a folder, for example, SHUT.BAT in C:\WINDOWS.

Then, to schedule it, type the following in the command line:

AT 17:15 C:\WINDOWS\SHUT.BAT

This will run without problems.

Here’s another way to do it:

If you want to schedule a batch file to run, you need to create the batch file first. For example:

@echo off
cd \
@echo off echo>> foto.bat
echo cd \>> foto.bat
echo start C:\PHOTOS\foto01>> foto.bat
echo exit>> foto.bat
at 14:13 C:\foto.bat
exit

And that will work.

Another, simpler code to start:

@echo off
start c:\rutadelaimagen\picture.jpg
exit

Put this into a batch file (e.g., imagen.bat).

Then, schedule the batch file manually by typing:

at 14:13 C:\rutadelbat\imagen.bat