up vote 6 down vote favorite
4
share [g+] share [fb]

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.

link|improve this question

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
1  
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
What language are you writing your service in? – Hugh Allen Oct 30 '09 at 5:53
feedback

7 Answers

up vote 8 down vote accepted

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

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

Solution 2:

Use a command line tool to silently launch a process : Quiet.

link|improve this answer
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
feedback

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"

link|improve this answer
But how would I run this command? – Moayad Mardini Oct 29 '09 at 13:01
1  
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
feedback

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("tasklist > C:\tasks.txt")
os.system("ipconfig /all > C:\netinfo.log")
link|improve this answer
1  
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
feedback

You can run it minimized easily.

start /MIN batch.cmd
link|improve this answer
feedback

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

link|improve this answer
feedback
cmdow /run /hid "file.extention" arg1 "arg 2"
link|improve this answer
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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.