Most ordinary Windows users never use the Command Prompt and have no idea what sort of things you can do from the command line. More experienced users will know that running command line commands can be very useful for a range of tasks and grouping everything into a single batch file to process it all together can be very powerful.
One inconvenient thing with running batch files is that they always open a console window which shows the output of the commands being executed. This can be important if you want to interact or see what is happening while the batch file is running but a bit of a pain if you want to run the batch script quietly in the background or while starting windows.
For short batch files the console window may appear and disappear in a flash or stay open for longer if more commands are being executed. There is no standard built in way to completely hide the console window from showing so if you want to do that another solution is required. Here we show you a number of different ways to make your batch script run silently without a console window showing.
Run a Silent Batch Script Using a Third Party Utility
A simple and common solution for running a batch file silently is launching it via a third party utility that suppresses the console window.Hidden Start (HStart)
Hidden Start is a portable and quite powerful tool that can launch batch files and scripts with a number of useful options. Besides the silent option to hide the console window it can also launch the script with elevated privileges, popup messages and even bypass UAC prompts altogether. Sadly the bypass UAC option is not free and only available in the registered version of HStart.
HStartUI.exe is a wizard interface consisting of three steps. First add or drop your batch file onto the window, then check the required options. Obviously “Hide console window” is the most important but other options like running with highest privileges could also be useful depending on your script. Step 3 shows the output command to be manually added into shortcuts or startup entries, you can use the buttons at the bottom to automatically create a shortcut or autostart entry.
Nirsoft’s NirCMD is a small multi function tool that is able to perform dozens of tasks without popping up any console window. These include ejecting ROM drives, changing audio volumes, enabling screensavers, controlling services and much more. The following command can be used at boot or in a shortcut to run a batch file silently:
nircmd elevatecmd exec hide [path to .bat file]
The exec and hide commands are used to execute the script and hide any console windows from opening. Use elevatecmd to request administrator privileges for the batch file although it’s only needed if the commands in your script require elevation.
You can tell NirCMD to create a desktop shortcut from the command line with the included commands so the silent script is ready to run:
nircmd cmdshortcut "~$folder.desktop$" "ElevateSilentBatch" elevatecmd exec hide C:\Scripts\MyBatchFile.bat
The above will create a desktop shortcut called ElevateSilentBatch which will silently execute the MyBatchFile.bat script while asking for administrator privileges before running it.
On double click NirCMD will offer the option to copy itself to the Windows directory so you only have to use nircmd.exe and not supply a full path every time. It’s advisable to do that if you plan to make use of NirCMD on your computer. For full information about the wealth of commands you can use have a read of the full NirCMD Help file.
This is a small (12KB) tool that is not blessed with tons of features but does the simple task which we are looking for. The syntax to use in shortcuts or similar is quite simple.
SilentCMD [path to .bat file] [arguments]
There is one option which is to enable logging, add “/log:[path to .txt]” to the command or “/log+:[path to .txt]” will append to an existing log file. As long as you don’t need extra functions like elevation or a different starting directory, SilentCMD might be all that you need.
Hide the Batch Console With a VBS Script
Being able to hide the batch script console window using Visual Basic is quite similar to using an external command and works in basically the same way. Launch the VBS script and supply the batch file as an argument, then the code runs the script while not showing any output. It can be done with a single line of code.
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
Create an empty text file, copy and paste the above line then save it as a .vbs file. Alternatively download launchquiet.vbs which is a script we’ve already created. To add it to a shortcut or a startup location etc, use the commands in the following way. Don’t forget to use quotes if your paths or filenames contain spaces.
Wscript [path to .vbs file] [path to .bat file]
If you would like to supply an argument for the batch file as well, the piece of VBscript has to be altered slightly by changing the two sets of four double quotes to two sets of two.
CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False
Then supply the arguments along with the batch script path inside quotes:
Wscript [path to .vbs file] “[path to .bat file] [argument]”
Again, for convenience you can download a ready made launchquiet_args.vbs script file.
Convert a Batch Script Into an Executable File
Another way to run a quiet batch file is by turning the script into an executable file. Using the right converter will give the option to suppress the window. One issue is a converted batch script can sometimes be flagged by security software as malicious, but it won’t be an issue if the program is for personal use.
Bat To Exe Converter
Bat To Exe Converter by F2KO Software is an easy converter to use while still offering additional features for intermediate and advanced users. A bonus is the downloaded Zip includes both installer and portable versions and a number of example batch files.
Drop a batch file onto the window or browse for it manually, select the Invisible application radio button and click Compile. This will auto create an executable with the same name as the batch script. The Add administrator manifest option is useful if your script has commands that require administrator privileges while UPX compression makes the executable smaller. The other options are more for advanced usage and not essential.
Another powerful feature is a number of built in script commands. You can add these into your script to make certain tasks which are normally difficult or not possible from the command line easy to accomplish, such as file requesters, message/input boxes, reading clipboard data or retrieving file checksums. There’s around 100 commands to use and you can edit your script from the built in editor which includes syntax highlighting. Read the manual for the commands and their usage.
The F2KO website also includes an online Bat To Exe converter which is essentially a cutdown version of the utility offering the basic functions.
Simply upload your batch script, check the invisible radio button, optionally check the Admin Manifest box and click Convert. The created executable will be inside a password protected Zip, the password is displayed on the webpage.
Slimm Bat To Exe Converter
Using the Slimm batch to executable converter is just about as easy as you could wish to get, but if you want a little more power a couple of extra options are also available. It’s also a portable tool.
To quickly create an executable from a batch file that won’t pop up a console window, click the Windowless Express button , browse for the script and it will automatically create the exe file at the same location as the batch file. The Custom button offers the chance to use a built in text editor where you can also add you own custom icon from the editor’s Tools > Options menu.
Download Slimm Bat To Exe Converter (Use developers CNET link as direct link is dead)
Create Your Own Executable File
This method is somewhat similar to turning a batch script into an executable, but you create the code and compile the program yourself. For that a programming or scripting language is required, we have chosen AutoIt but you can use the similar AutoHotkey or something else if you have another favorite.
Here are 4 lines of AutoIt code to produce a quietly running batch file:
FileInstall("MyBatchFile.bat", @TempDir & "\MyBatchFile.bat",1)
Run(@ComSpec & " /c " & @TempDir & "\MyBatchFile.bat", "", @SW_HIDE)
The code is simple to understand, line 1 is optional and asks for administrator privileges, line 2 is also optional and compresses the executable. Line 3 embeds the MyBatchFile.bat in the executable and extracts it to the Windows Temp folder on launch, while the final line runs the batch file as a console command with the hide attribute suppressing the window.
To simplify the process you can compile the executable with just the last line if you want to run a batch file silently that is stored in a permanent location on your computer.
Run(@ComSpec & " /c " & "C:\Scripts\MyBatchFile.bat", "", @SW_HIDE)
The above will silently execute MyBatchFile.bat from the C:\Scripts folder. To use AutoIt all you have to do is install it or use the portable version, create your code and press F7 to compile. Make sure the batch file to embed is placed in the same folder as the .au3 AutoIt script file.
Run a Silent Batch Script Using a Scheduled Task
While it’s easy to use the above methods to run a scheduled task, it’s also possible to silently run a batch file without using any of them. All you have to do is point to the batch file and tick a few boxes, this is obviously best for scripts launching on startup, logon or at a specific date and time.
1. Go to Control Panel > Administrative Tools > Task Scheduler, or type taskschd.msc into the Start search box or the Run dialog.
2. Click Create Basic Task and give the task a name, click Next and select when you would like to launch the task. In the Action window leave “Start a program” selected and after clicking Next browse for the batch script. Before finishing the wizard check the box to open the properties dialog.
3. In the Properties window select “Run whether user is logged on or not“, you will need to have and enter a user account password when task editing is complete. If there’s no password on the account tick the “Do not store password” box. This does have a drawback because the batch script will not be able to access file, folder or printer shares.
4. If the batch script needs administrator privileges tick the “Run with highest privileges” box. Click OK when done,
Now you can test the task works by right clicking and selecting Run or waiting for it to run at the scheduled time. It should work and without popping up any type of console window.
Final Note: When using a method to hide the console window make sure that the batch script itself contains no commands that are likely to stop the script before it exits, such as pause or choice. If the script stalls which has been converted into an executable for example, you won’t be able to interact with it and the process will stay in Task Manager until it’s manually killed.