35
votes

After Windows XP, I always use the trick below to start batch files minimized with Windows Task Manager.

From http://www.pcreview.co.uk/forums/running-bat-files-minimized-scheduler-t2125918.html:

"prequisite: all your batch files have an exit-command to finish the actions off. If you do not exit, you will end with a command prompt blinking.

This is what I keep using:

%comspec% /c start /min "C:\Scripts\Destination_inbound_ftp5.bat"

When you save this in the properties, you will get a follow-up dialogue asking you if you meant all this to be parameters or not. Answer NO and the task will be saved as you would expect.

I also read the Stack Overflow question “start %comspec% /c script.cmd” vs “start cmd /C second.cmd script.cmd”, which made me replace the "%comspec%" statement with "C:\Windows\system32\cmd.exe", but that did not change anything either.

The problem is that now, instead of a minimized running bat file, I end up with just a command prompt, minimized but without any of the batch commands executed. The task scheduler status remains "running" :(

How do I get this done on Windows 8 (64-bit)? Preferrable with old-school batch commands instead of PowerShell (or worse ;p)

7
There's a tick next to answers. Make sure you accept the answer that works for you - and you can also change it later if you need to.foxidrive
perhaps the simplest way to run a scheduled task in a minimized / hidden state (no flashing command-line windows) is to launch the Task Scheduler console, right-click on the task you want to run in the background and choose Properties, then enable the 'Hidden' option AND also click 'Run whether user is logged on or not'. this method will run the scheduled task silently, without opening any windows whatsoever.user1082

7 Answers

33
votes

The start command needs the leading "" quotes to disable the title feature. Try scheduling this:

%comspec% /c start "" /min "C:\Scripts\Destination_inbound_ftp5.bat"  ^& exit
26
votes

Assuming Windows 8 is the same as Windows 7, an "exit" is only going to exit the batch file (which it is going to do anyway).

You need to add the exit code like this:

Under "Program/Script":

CMD (or command.exe, or %comspec%)

Under "Arguments:

/c start "Title" /min "C:\Scripts\Destination_inbound_ftp5.bat" ^& exit
7
votes

I didn't like seeing the command window pop up and then disappear so here is another solution from https://ss64.com/vb/run.html ...

First create invisible.vbs with this single line of text:

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

Next and finally, launch your cmd or batch file via:

%SystemRoot%\system32\wscript.exe "invisible.vbs" "myscript.cmd" //nologo

Ta da! Scripting of this sort has been built into Windows for a long time. If you're curious, do a web search for "WSH" (windows scripting host). You can even write such scripts in dialect of JavaScript called JScript.

5
votes

Another possibility: a small freeware program named CMDH, that simply runs the requested orders in background. For example:

cmdh MyScript.cmd

No need to add "exit" to the script. Tested working in Windows XP SP3, and there is no reason it should fail on Windows 8.

4
votes

Here's a solution from https://ss64.com/vb/run.html that will run a batch file in a minimized window. Unlike the other solutions that use the start command with /min, this one will not flash a new window onto your screen or interrupt full-screen activities. It does, however, steal focus. I don't know how to avoid that.

First create a file named run_minimized.vbs with this single line of text:

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

Next, create your Task Scheduler task with an action to start the program wscript.exe with these arguments:

"c:\path\run_minimized.vbs" "c:\path\my script.bat"

Change the paths as necessary to specify the locations of the two files.

There is no simple way to pass arguments from Task Scheduler to the batch file while also preserving spaces and quotation marks, because wscript strips quotation marks from its arguments. The simplest way to handle arguments with spaces would be to put the entire batch file command into the vbs:

CreateObject("Wscript.Shell").Run  """c:\path\my script.bat"" ""arg 1"" arg2", 2, False

Note the use of quotation marks. There's one pair of quotation marks " enclosing the entire command string, and a pair of adjacent quote characters "" every place you'd use a normal quotation mark in a command line.

1
votes

Maybe it's not the same as you mean but if I simply run a .bat file with the scheduler and tick this "Hidden" box on the General tab of the task properties it starts minified.

enter image description here

0
votes

As already mentioned in foxidrive's answer, the issue is caused by the missing title parameter, which is taken from the first quoted argument string on the command line of the start command, which is the quoted batch file path in your command line. Since there is nothinbg left to be taken as the command/program to be started, the default cmd.exe is started.

Providing a dummy title (which may even be empty) solves that issue:

%ComSpec% /C start "" /MIN "C:\Scripts\Destination_inbound_ftp5.bat"

However, as mentioned in the help message of start (type start /? into a command prompt window), when the provided command/program is a batch file, the command processor cmd.exe is run with the /K switch, which keeps the command prompt window open:

    command/program
                If it is an internal cmd command or a batch file then
                the command processor is run with the /K switch to cmd.exe.
                This means that the window will remain after the command
                has been run.

                If it is not an internal cmd command or batch file then
                it is a program and will run as either a windowed application
                or a console application.

To prevent that, let us explicitly specify the command processor with the /C switch:

%ComSpec% /C start "" /MIN %ComSpec% /C "C:\Scripts\Destination_inbound_ftp5.bat"

So there is no additional exit command necessary.