Hide The Running Batch File Using Visual Basic Script

Batch file

This how-to article is straightforward and to the point. In this post, you will learn how to run batch files in hidden mode. Many times, you need to run hidden batch files  just to keep them safe; not to get closed mistakenly. I remember, years back when I logged into the server machine for the first time in my office my manager asked me promptly not to close any command line window for any reason because many applications were running through these batch files in production. Not just this, but there were Jenkin slave machines, logger servers of the main application product of my company, telnet, and few others instances were running based on these batch files, thus the first thing I did was make those running batch files run in the hidden mode (it goes differently from case to case) so only the intended people would have access to them and shutting those servers down will be less onerous.

Batch files? – why do I use them?

A batch file contains some scripts or commands to run sequentially with the help of command line interpreter, these commands run faster to make these script files useful for logging services, to automate some jobs and to configure some services within the Microsoft Windows environment. The best thing about batch scripts (which I’ve figured out) is their syntax which doesn’t get changed. It remains the same with all the versions of the Windows operating system, so the scripts written once will do the job for years. Furthermore, writing some complex commands in the command prompt or shell isn’t that easy to do over and over again; it’s better to write them down once in a notepad file with a .bat extension to force those commands to run in a collected sequential manner.

Run batch file invisibly

There are multiple ways to achieve this but the handiest is to write a visual basic script to run your batch file (writing a script to make another script run safely) in hidden mode.

  1. Set WshShell = CreateObject("WScript.Shell")  
  2. WshShell.Run chr(34) & " C:\Users\Foobar\Machines\ML\StartMLStudio.bat" & Chr(34), 0  
  3. Set WshShell = Nothing  

The first line will start the command line window shell process on which you will run the further commands, then we have set the character set for the text string and finally, we have given the path of the hidden batch file we want to run.

Copy the code, change the path, save the file with .vbs extension to run hidden batch files contained in the script and enjoy.

Note

I prefer to place this hiderunningbatchscript.bat file in the same directory where you have placed your batch.bat file itself, it’s not necessary in all cases but within few environments, it doesn’t work if kept somewhere separate.


Similar Articles