How to Run Batch Script in Silent Mode
-
Run Batch Script in Silent Mode Using the
@echo off
Command - Run Batch Script Silently Using Third-Party Software
- Run Batch Script Silently Using VB Script
- Run Batch Script Silently Using Task Scheduler
If you run the CMD without the silent mode, the command prompt will print every line of the code in CMD. This article will show how to activate the CMD silent mode through the Batch script.
We will also learn different ways we can run the Batch script silently. We will look at some examples and explanations to make the topic easier.
Run Batch Script in Silent Mode Using the @echo off
Command
A built-in command in Batch named echo
is used for several purposes in the script. We will include the @
with the command echo
.
Suppose you add the command @echo off
at the beginning of the script. Let’s see the below example.
SET /A x = 15
SET /A y = 25
SET /A z = %x% + %y%
ECHO The sum of a and b is %z%
IF %z% LSS 20 (echo The result is less than 20) ELSE (echo The result is greater than 20)
In the example above, we added two numbers and checked whether the number was less than 20. But the main point is that if you don’t use the command @echo off
at the beginning of the code, you will get an output like the one below.
Output:
C:\Destination\Author>SET /A x = 15
C:\Destination\Author>SET /A y = 25
C:\Destination\Author>SET /A z = 15 + 25
C:\Destination\Author>ECHO The sum of a and b is 40
The sum of a and b is 40
C:\Destination\Author>IF 40 LSS 20 (echo The result is less than 20 ) ELSE (echo The result is greater than 20 )
The result is greater than 20
Now, if you use the command @echo off
at the beginning of your script, your output will look like this:
The sum of a and b is 40
The result is greater than 20
So, the command @echo off
will turn off displaying each line in the Batch script and provide a nice output.
Run Batch Script Silently Using Third-Party Software
Below, we shared some third-party software you can use to execute Batch scripts.
Hidden Start (HStart)
The Hidden Start is a powerful and portable tool through which you can launch scripts and executables by applying several options. You will have options like Hide console window
, Run with highest privileges
, etc.
To run a batch script with the help of this third-party software, you only need to provide the file’s location and add it to the executable file.
SilentCMD
SilentCMD is a small and lite weight third-party tool you can use to run Batch scripts. The basic syntax when running a batch script with SilentCMD is:
SilentCMD [path to your file] [your batch arguments] [ available options]
NirCMD
NirCMD is a third-party software created by NirSoft. It is a small tool with multi-functionality to perform several tasks without opening any console window.
The general syntax using this third-party software is:
nircmd exec hide [ Your Path to file]
Run Batch Script Silently Using VB Script
You can run a Batch file using Visual Basic script. To run a batch script with the help of the VB script, you can follow the below example:
SET WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\YourLocation\YourScript.bat" & Chr(34), 0
SET WshShell = Nothing
Run Batch Script Silently Using Task Scheduler
You can also run a Batch script by Task Scheduler as a scheduled task. To do that, you have to follow the below steps:
-
Open the Task Scheduler.
-
Now, click on the
Create Task
. -
Provide a name and necessary information here.
-
Now, click on the
Actions
tab and then click onNew
. -
Now provide the exact location of your Batch Script, select action, and provide optional settings if necessary.
-
Lastly, click on
OK
in both opened windows.
Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.
LinkedIn