how to create a batch file - basics

 

A simple batch file is a text file containing a set of command prompt commands. A simple editor is sufficient to create the batch file. A text file saved in Windows/DOS with the extension .cmd or .bat, can be executed directly. Especially for very simple processes, for example copying files or folders, batch files may still be easier than using PowerShell. At the latest, if commands should not be executed in sequence and certain if-queries, loops or functions are necessary, I would recommend the use of PowerShell.

Create a Batch-File

A new batch file can be created in any editor. .cmd or .bat should be used as the file extension. In the Windows editor, the file name should be placed under quotation marks so that “batchfile.cmd.txt” is not saved as the extension, but “batchfile.cmd”:



Batch commands are then written to the file in a separate line each time. When executing the file (double click) the lines are processed one after the other.
A right click “edit” opens the editor again to edit the file.

Video

See also: Structure of a Batch File Syntax

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Updated: 2023-02-28 von Bernhard | Übersetzung Deutsch |🔔 | Comments:0

Windows Batch | Practical examples with batch

Top articles in this section


Execute remote commands with psexec pstools - cmd Windows

The pstools can be used to execute commands on other computers: Of course, this requires the necessary rights for the remote connection: by default, these are the domain administrator or the local administrator. As an alternative for a remote connection to another computer, PowerShell remoting can also be used, see: Powershell Remote


Practical examples with batch

Handling variables in Windows Batch (command prompt) Read all variables Variables can be read out in the command prompt with the set command:


Structure of a batch file Syntax: echo off cmd

If you have created a batch file, you can write a command in each line, see: how to create a batch file - basics. The commands are executed in sequence when the file is started. The behavior of the output can be adjusted as follows:

Questions / Comments