Automation batch files for Windows are becoming more and more popular, it is even more important to correctly name and use the batch, which is often referred to as a script!A batch file is usually not a script but a batch processing file which is an executable text file, the commands are executed line by line, environment variables can be used here and programs can be started on MS Windows 11, 10, ... Desktop and all Microsoft server operating systems! 1.) ... Creating a batch file via the command prompt!
|
(Image-1) Create a batch file on and for all MS Windows OS! |
2.) Editing the batch files in the text editor!
Editing the batch files is easy, any text editor can be used1. Start the text editor (Windows + R and command notepad)
2. In the editor go to the menu ► File ► Open
3. And enter the path of the batch files , for example: C:\Test\Test_Batch.bat
You can also start editing your batch file with Notepad from the command prompt by typing:
notepad C:\Test\Test_Batch.bat
You can also do it directly via the Run dialog:
Windows + R notepad C:\Path_of\Test_Batch.bat
(... see Image-2 Point 1 to 3)
(Image-2) Edit batch file under MS Windows OS! |
3.) Use the help for internal commands and programs!
Use the help to achieve better / desired results for internal commands and programs, for most you can get help with the "help" command or "/?"
For example:
help dir
or:
dir /?
4.) Running the batch files on all MS Windows OS!
Executing the batch files on all MS Windows OS and other operating systems can be done from another batch file, which allows nesting and multiple use!However, they are usually started via the command prompt, the Enter key in MS Explorer, or a simple mouse click!
Adding to the startup folder is also possible to perform certain tasks at system startup!
For example: Add batch file to autostart to save time:
►► Use batch file to start multiple programs!
Run example from command prompt
C:> C:\Test\Test_Batch.bat
In some cases you may need to run with elevated privileges, if that is the case, right click and select "Run as Administrator"
►► Windows 11, 10, 8.1, ... Run programs as administrator?
5.) What is the difference between scripts and batch files?
There is much debate around the two terms, is a "batch file" a script or not. And when is it a script!The main difference is that a batch file is a list of commands to be executed, mostly doing the actual work in the programs that are controlled/used from the batch file,... while scripts have more own functions/ have sub-programs and sometimes carry out independent tasks.
Batch files are very old, and can be seen as the first version of script files originating from MS-DOS and UNIX. But these are still used in all versions of Windows, including LINUX and MAC OS!
But you don't have to worry about whether a batch file is a script, the purpose is much more important!
6.) What advantages do I have by using batch files!
It's primarily about automation, but also about saving time and avoiding errors when tasks have to be carried out again and again or have to be adjusted!
You can adapt a created bat file at any time, for example if you add further commands or change directories!
7.) Tips and examples with batch files!
►► Waiting for keyboard input Command prompt script?
►► Generate random numbers in command prompt or batch file!
►► Use batch file to start multiple programs!
►► How can I run commands in batch files at intervals?
►► Command line arguments in the command prompt with examples?
►► or in the Windows Console FAQ!
FAQ 138: Updated on: 26 August 2023 11:00