How to run scheduled .bat file without opening a window?

V

Vanguard

I want to add a scheduled event in Task Scheduler to run a .bat file every
10 or 20 minutes. The problem is that this results in opening a console
window while the batch file is running. I don't want to have my work
interrupted by a window popping up all the time for a job that should be
running in the background.

At first, the command for the event was "C:\Batch\<batfile>.bat" but that
opens a DOS shell console window when it gets executed. I then tried "cmd
/c start /b C:\Batch\<batfile>.bat" but that opens a console window (and
leaves it open). I ran "cmd /?" but none of the command-line switches let
me tell it not to open a console window.
 
R

Ramesh, MS-MVP

B

billious

Vanguard said:
I want to add a scheduled event in Task Scheduler to run a .bat file every
10 or 20 minutes. The problem is that this results in opening a console
window while the batch file is running. I don't want to have my work
interrupted by a window popping up all the time for a job that should be
running in the background.

At first, the command for the event was "C:\Batch\<batfile>.bat" but that
opens a DOS shell console window when it gets executed. I then tried "cmd
/c start /b C:\Batch\<batfile>.bat" but that opens a console window (and
leaves it open). I ran "cmd /?" but none of the command-line switches let
me tell it not to open a console window.

--
__________________________________________________
Post replies to the newsgroup - Share with others.
E-mail: Remove "NIX" and append "#LAH" to Subject.
__________________________________________________

would

START /MIN "" c:\batch\batfile.bat

do what you want (Personally, I'd add the /LOW switch too)

HTH

....Bill
 
W

W3

You could create a shortcut to the bat file and set properties to run
minimized. You will see it appear in the Taskbar only while it runs.
 
V

Vanguard

billious said:
would

START /MIN "" c:\batch\batfile.bat

do what you want (Personally, I'd add the /LOW switch too)


Unfortunately "start" is an internal command (to cmd.exe). That means
cmd.exe displays its console window before it even parses the "/c start /min
...." string. So what I would see is cmd's console window flash on the
screen. This is less intrusive than before. The .bat file takes a split
second to run, so the difference between its console window with or without
the start command (with or without the /min switch) versus just running the
..bat file (which also loads its own DOS shell with console window) is so
small that it would be difficult to tell which flash is faster. Thanks for
trying to come with something, though.
 
V

Vanguard

W3 said:
You could create a shortcut to the bat file and set properties to run
minimized. You will see it appear in the Taskbar only while it runs.


Well, that's pretty good. I created the shortcut (which also lets me
specify the command-line parameters that I had to specify in the Command
specified in the scheduled event in Task Scheduler). I set the property to
open it minimized. Then I had to figure out how to get the shortcut in Task
Scheduler. LNK files aren't something you can browse to. So I simply
entered "C:\Batch\<shortcutname>.lnk" in Command and it worked. When the
Task Scheduler runs the scheduled event which executes the .lnk shortcut
with its minimized windows, all I see is a momentary flash of its button in
the Windows taskbar (how long depends on how long it takes to run the batch
file).

It's a pity that you cannot run [DOS] programs truly in the background
(i.e., without *any* console window), except perhaps how Ramesh mentions by
using VBS and specifying an attribute (of no window) for the shell that it
opens. However, I wanted to keep the solution simple so anyone else later
using or maintaining that host could figure out what I did and would know
how it worked. VBS pretty much eliminates most users.
 
V

Vanguard

Ramesh said:
You may use a VBScript to call the batch file:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.asp

intWindowStyle
Optional. Integer value indicating the appearance of the program's window.
Note that not all programs make use of this information.

intWindowStyle Description
0 Hides the window and activates another window.


Thanks, but I wanted to stay away from anything programming-like so anyone
that ends up having to manage this host could figure out what I did and
would know how it worked (so they could maintain the process). I didn't
want to require Perl, VBS, or even much knowledge in .bat coding for them to
know how they might have to maintain the process. I'm a contractor and
leaving in a month and have no idea of the talents of whomever gets stuck
maintaining this host.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top