# Run a batch file in a completely hidden way

I'm looking for some way to run a batch file (.bat) without anything visible to the user (no window, no taskbar name, .etc..).

I don't want to use some program to do that, I'm looking for something cleaner. I've found a solution that uses VBScript, but I don't really like using VBS, either.

-
Haha! Definitely not. I'm developing a Windows service which will run a batch file every now and then. –  Moayad Mardini Oct 29 '09 at 12:53
Windows services don't run as batch files. They run as services. You need to clarify the question--as written and with comments it makes no sense to me. –  CarlF Oct 29 '09 at 14:03
I has a Windows service that runs batch files. Not that the service is a batch file. –  Moayad Mardini Oct 29 '09 at 18:37
there is hstart too. –  barlop Dec 10 '13 at 20:55

Solution 1:

Save this one line of text as file invisible.vbs:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

To run any program or batch file invisibly, use it like this:

wscript.exe "C:\Wherever\invisible.vbs" "C:\Some Other Place\MyBatchFile.bat"

To also be able to pass-on/relay a list of arguments use only two double quotes

CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False

Example: Invisible.vbs "Kill.vbs ME.exe"

Solution 2:

Use a command line tool to silently launch a process : Quiet, hidecon or hideexec.

-
Why 4 double quotes, could you please explain? –  Starx Jul 28 '11 at 7:44
What if we needed to start a program hidden? –  Starx Jul 28 '11 at 9:57
@Starx VB syntax. & means concatenate strings. Strings are enclosed in double quotes ("). Consecutive double quotes ("") inside string delimiters means a literal double quote ("). So, four double quotes ("""") would be a string literal of one character, a double quote ("). Put it together, and """" & WScript.Arguments(0) & """" would become "<argument>", where <argument> is the first command line argument passed to the script. –  Bob Dec 17 '12 at 17:39
Cool and simple solution. Checked it, it works. Thanx. –  nightcoder Dec 23 '12 at 16:08
Finally, after hours of wasted time searching and trying, this one liner VBS does the trick. Simplest solution for starting batch file silently from scheduled task, thank-you. –  Mr. Bungle May 12 '13 at 20:46

To Hide batch files or command files or any files.... Use Windows XP built in Iexpress.exe utility to build a .EXE out of the batch file. When using Iexpress make sure you check the run hidden option and check mark all the boxes about not showing anything. After you create your .exe place it in whatever run command folder you choose and you will never see it come up.

-
Oh, good solution actually. –  Camilo Martin Sep 8 '12 at 1:34

use Cmdow is a Win32 commandline utility for NT4/2000/XP/2003 that allows windows to be listed, moved, resized, renamed, hidden/unhidden, disabled/enabled, minimized, maximized, restored, activated/inactivated, closed, killed and more.

Run a batch file hidden passing it parameters:-

cmdow /run /hid mybat arg1 "arg 2"

-
But how would I run this command? –  Moayad Mardini Oct 29 '09 at 13:01
cmdow is detected as a malware by most antivirus products. Hence it would be difficult to use this solution in places other than you own PC. –  Ganesh R. Oct 29 '09 at 13:02
@Ganesh: Any better solution? –  Moayad Mardini Oct 29 '09 at 13:04

Seems that somebody made a list of the 7-8 ways to run 'silent':

http://forums.techguy.org/dos-other/644932-solved-howto-run-batch-file.html

-

Run the script via an at job without making it interactive:

at 11:00 script.bat


Another solution, if you don't mind installing something like Python, you could simply create a script and run it with pythonw (the linked version for GUI operations). Since you aren't using any graphical APIs, the window will not show. Simply use calls to os.system() and it will mimic a batch script, as it is the same as typing the strings into the command line.

Example:

import os

os.system("ipconfig /all > C:\netinfo.log")

-
But how would I run this command? –  Moayad Mardini Oct 29 '09 at 13:07
You would have to either schedule a scheduled task or write a service. –  MrStatic Oct 29 '09 at 13:26
examples added. –  John T Oct 29 '09 at 14:44

You can run it minimized easily.

start /MIN batch.cmd

-

If your Batch File can fit into one line and so many characters, then just use a Shortcut by right clicking inside a folder put in a random directory, and skip through the rest of the wizard, and lastly right click on the shortcut just created and click properties and under target, input what you would usually put in a bat file. And Bobs your uncle!

Pros:

 No Command Window
Ability to use an icon
Same Functionality of bat file


Cons:

 Limited to one line, so many characters

-
excellent answer, for me –  johny why May 1 '13 at 18:16
The only problem is that you can't associate a filetype with a shortcut. So if you want to open a with a batch script by double-clicking on it in explorer you still need a .bat-file. –  Björn Lindqvist Jan 24 at 15:40

You do not need to do any special.

If you are running the batch files from a windows service, they should be hidden by default unless you enable the "Allow service to interact with desktop" option on the service.

-

Using Windows7, you can use the "Scheduled Task" control panel to schedule a batch file to run in the background invisibly with specified permissions and even as the "SYSTEM" account. See screenshot below:

Furthermore, although with not as many capabilities, you can also create a invisible batch script task like this from the command line using the "AT.exe" command without the '/interactive' option.

-

I don't like VBScript solution.

Download and copy nircmd.exe to your %systemroot%\system32 folder, then add this command to first line of your batch:

nircmd.exe win hide ititle "cmd.exe"


or make your batch title custom first with title command to avoid from hiding all cmd windows, like this:

title MyBatch
nircmd.exe win hide ititle "MyBatch"

-
cmdow /run /hid "file.extention" arg1 "arg 2"

-
Please include brief explanation of the command. That might help the OP (and others) understand how it works instead of just copying the command and using it. –  BloodPhilia Jan 26 '11 at 20:07
commandline.co.uk/cmdow –  paradroid May 25 '11 at 3:30

I'm experimenting with SCHTASKS. The idea is that if schedule a task as SYSTEM user the process will be started as hidden.And if you delete a scheduled task the process will be not stopped.Here's more info : http://ss64.org/viewtopic.php?id=1539

-

I had the same problem, but figured it out:
 Shell("filehere" & "parametersforbatchfilehere", vbHidden) 

-

This works for windows 8 (possibly others)

1. Create a batch file as normal
2. Create a shortcut to the batch file
3. Right click on the shortcut > properties
4. Click Layout
5. Untick "Let system position window"
6. set left position tp -1000
7. click apply

8. Click on the shortcut and it will run but you wont see it :)

-
Really? This won't show as a button on the taskbar? –  Scott Aug 16 at 0:23

I started trying to figure this out and never really succeeded. This was as close as I got:

@echo off
if not defined PIL (
set PIL=1
start /min "" %~0
exit /b
)
TITLE Hello World
echo Hello world!
pause>nul

-