Windows Batch

Below are a few examples and code snippets useful to manipulate the windows command line. Creating batch jobs for the windows command interpreter is a good skill to have up your sleeve and being able to automate tasks here will save you a lot of time in the long run.
loading template

The Loading Template
The batch loading template is useful if your batch script is set to iterate through a series of tasks before executing the main content of the script. This allows for a visual representation of the script working those tasks and an indication of the progress.
The script is simply ASCII block characters that step forward after each event or task that has completed giving the look of a progress bar progressing.
This step is processed by counter variable addition (inti and intk) and a if condition checking the values resulting in what state the progress bar will be displayed in the batch window.
For the template notice the ping -n 2 127.0.0.1>nul under the number headings to simulate tasks being run. This command actually pings the localhost with 2 packets however the >nul disposes of the output. I like using this statement for short breaks in the scripts. Remove the 'pause' from after the MAIN lable after you have added your running tasks.
The script is simply ASCII block characters that step forward after each event or task that has completed giving the look of a progress bar progressing.
This step is processed by counter variable addition (inti and intk) and a if condition checking the values resulting in what state the progress bar will be displayed in the batch window.
For the template notice the ping -n 2 127.0.0.1>nul under the number headings to simulate tasks being run. This command actually pings the localhost with 2 packets however the >nul disposes of the output. I like using this statement for short breaks in the scripts. Remove the 'pause' from after the MAIN lable after you have added your running tasks.
![]()
|
|
@echo off
:HEAD
setlocal
:START
color ec
set strStartcurrent=Building -template...
set inti=0
set intk=15
:STARTTITLE
title= Script name... - Loading...%strStartcurrent%
set /a inti+=1
cls
echo.
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º º
echo º .-title.... º
echo º LOADING º
echo º º
if %inti% LSS %intk% (
if "%inti%"=="1" (echo º [.............] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 1)
if "%inti%"=="2" (echo º [Û ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 2)
if "%inti%"=="3" (echo º [ÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 3)
if "%inti%"=="4" (echo º [ÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 4)
if "%inti%"=="5" (echo º [ÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 5)
if "%inti%"=="6" (echo º [ÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 6)
if "%inti%"=="7" (echo º [ÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 7)
if "%inti%"=="8" (echo º [ÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 8)
if "%inti%"=="9" (echo º [ÛÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 9)
if "%inti%"=="10" (echo º [ÛÛÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 10)
if "%inti%"=="11" (echo º [ÛÛÛÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 11)
if "%inti%"=="12" (echo º [ÛÛÛÛÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 12)
if "%inti%"=="13" (echo º [ÛÛÛÛÛÛÛÛÛÛÛÛ ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 13)
if "%inti%"=="14" (echo º [ÛÛÛÛÛÛÛÛÛÛÛÛÛ] º) & (echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ) & (ping -n 1 127.0.0.1>nul) & (GOTO 14)
)
echo º [ÛÛÛÛÛÛÛÛÛÛÛÛÛ] º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
GOTO 15
:1
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:2
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:3
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:4
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:5
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:6
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:7
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:8
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:9
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:10
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:11
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:12
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:13
ping -n 1 127.0.0.1>nul
GOTO STARTTITLE
:14
ping -n 2 127.0.0.1>nul
GOTO STARTTITLE
:15
echo.
:MAIN
pause
:END
EXIT
Batch beep

A beep from your batch file is handy as a notification for users of incorrect input or to grab attention after you have scripted some events.
To output the system bell 'beep' sound from your batch file you need one of three things:
To type the ASCII charactor into your batch file hold the left ALT and press the number 7 on your number pad. You will need a full size keyboard for this. A laptop keyboard will not work.
You can find a list of other ASCII charactors to give your batch scripts like here.
To output the system bell 'beep' sound from your batch file you need one of three things:
- A full length keyboard to type the ASCII character into your batch file that represents the system bell;
- Copy and paste the code below into your batch file; or
- Download the batch_beep.bat file below.
To type the ASCII charactor into your batch file hold the left ALT and press the number 7 on your number pad. You will need a full size keyboard for this. A laptop keyboard will not work.
You can find a list of other ASCII charactors to give your batch scripts like here.

batch_beep.bat | |
File Size: | 0 kb |
File Type: | bat |
|
|