Creating batch files

by Flo

To create and programme batch files, all you need is the Microsoft text editor – and of course batch commands. In this practical tip you will learn how to create batch files with the help of small sample programmes.

Create batch files: How to proceed

With batch files you can write small programmes and thus, for example, write a programme with which you can shut down the computer with a comment and a time of 20 seconds. To do this, proceed as follows.

  • Open the editor and start typing with “@echo off”.
  • in the next line enter the command “echo Do you really want to shut down the computer?”. This is followed by the command “pause”.
  • On the next line, type “shutdown -s -c ‘This PC will shut down in 20 seconds’ -t 20”.
  • Now you have to save the file as a batch file. To do this, click on “File” and “Save as”. Select “All files” under “File type” and navigate to the desired storage location.
  • You can specify a name of your choice under “File name”. However, it is important that the name is followed by the extension “.bat”. For example, the programme can be called “Shutdown.bat”. Confirm by clicking on “Save”.
  • If you now double-click on the file, the programme will be executed and the PC will shut down after 20 seconds.

 

Other batch commands

Even though batch files are just simple programs, you can do a lot with them. You can get all batch commands by entering “help” in the command prompt. As an example, here is a small programme that terminates processes and starts the browser with google.de. You must confirm each step with a keystroke.

    • Open the editor again and start with “@echo off”.
    • Enter “taskkill /IM chrome.exe” below to kill Chrome. You can find more processes by typing “tasklist” in the console.
    • In the next line, enter “pause”. Windows will now wait for your next input.
    • The last thing you want to do is open google.com. To do this, enter “start chrome.exe https://www.google.de/”.
    • You can save the file as a batch file using the instructions described above and start it by double-clicking on it.

Related Articles

Leave a Comment