Running .bat files minimized from scheduler

  • Thread starter Thread starter Ken Levy
  • Start date Start date
K

Ken Levy

I have some .bat files which are run from the Windows Scheduled Task list.

The problem is that a DOS box pops up whenever these tasks are executed.
I'd like to run the tasks minimized so that the normal windows desktop
doesn't get covered up by these tasks.

There is no properties for the .bat file that I can set to run the task
minimized. I tried creating a shortcut for the .bat file which does have a
property tab with a setting for the startup mode. Every time I try to
change my Scheduled task to use the shortcut (.lnk) file, though, it
switches the filename back to the object of the .lnk file (the original
batch file) rather than keeping the .lnk file in the target filename field.

Can anyone suggest a way for me to hide (or at least minimize) these started
tasks?

Thanks in advance for any assistance. Please posts replies to the
newsgroup.

Ken
 
From: "Ken Levy" <[email protected]>

| I have some .bat files which are run from the Windows Scheduled Task list.
|
| The problem is that a DOS box pops up whenever these tasks are executed.
| I'd like to run the tasks minimized so that the normal windows desktop
| doesn't get covered up by these tasks.
|
| There is no properties for the .bat file that I can set to run the task
| minimized. I tried creating a shortcut for the .bat file which does have a
| property tab with a setting for the startup mode. Every time I try to
| change my Scheduled task to use the shortcut (.lnk) file, though, it
| switches the filename back to the object of the .lnk file (the original
| batch file) rather than keeping the .lnk file in the target filename field.
|
| Can anyone suggest a way for me to hide (or at least minimize) these started
| tasks?
|
| Thanks in advance for any assistance. Please posts replies to the
| newsgroup.
|
| Ken
|

Execute;

start /min filename.bat

as the task in .JOB file.
 
Ken Levy said:
I have some .bat files which are run from the Windows Scheduled Task list.

The problem is that a DOS box pops up whenever these tasks are executed.
I'd like to run the tasks minimized so that the normal windows desktop
doesn't get covered up by these tasks.

There is no properties for the .bat file that I can set to run the task
minimized. I tried creating a shortcut for the .bat file which does have a
property tab with a setting for the startup mode. Every time I try to
change my Scheduled task to use the shortcut (.lnk) file, though, it
switches the filename back to the object of the .lnk file (the original
batch file) rather than keeping the .lnk file in the target filename field.

Can anyone suggest a way for me to hide (or at least minimize) these started
tasks?

Thanks in advance for any assistance. Please posts replies to the
newsgroup.

Ken

When creating the scheduled task, specify an account other
than your own.
 
Dave:

Thanks for the quick response. I read the doc for the start command and it
certainly sounds like what I need.

I tried changing the Run command in the Scheduled task to:

start /min C:\Scripts\Destination_inbound_ftp5.bat

but the job did not start. Here is what is in the log . . .

"Destination_inbound_ftp5.job" (start) 9/7/2005 4:45:00 PM ** ERROR **
Unable to start task.
The specific error is:
0x80070002: The system cannot find the file specified.

If I remove the "start /min ", the job runs just fine, so the batch file
path and filename are correct. Does the start command have to be fully
qualified with a path? I did a search for it in the WINNT directory and
could not find it. Is it an internal command?

Any other suggestions? This one has me stumped . . .
Thanks.

Ken
 
From: "Ken Levy" <[email protected]>

| Dave:
|
| Thanks for the quick response. I read the doc for the start command and it
| certainly sounds like what I need.
|
| I tried changing the Run command in the Scheduled task to:
|
| start /min C:\Scripts\Destination_inbound_ftp5.bat
|
| but the job did not start. Here is what is in the log . . .
|
| "Destination_inbound_ftp5.job" (start) 9/7/2005 4:45:00 PM ** ERROR **
| Unable to start task.
| The specific error is:
| 0x80070002: The system cannot find the file specified.
|
| If I remove the "start /min ", the job runs just fine, so the batch file
| path and filename are correct. Does the start command have to be fully
| qualified with a path? I did a search for it in the WINNT directory and
| could not find it. Is it an internal command?
|
| Any other suggestions? This one has me stumped . . .
| Thanks.
|
| Ken

Change that to:

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

You have a long file name and it needs to be in quotes. Note that in my example I used a
BAT file using 8.3 naming convention so no quotes were needed. However, I made the mistake
in not using '%comspec% /c' in my example as this is needed for Start to be used as Start
is an internal command for both COMMAND.COM and CMD.EXE.
 
Try this instead:

start /b /min "My Scheduled Task" "C:\Scripts\Destination_inbound_ftp5.bat"
 
Ken said:
I have some .bat files which are run from the Windows Scheduled Task list.

The problem is that a DOS box pops up whenever these tasks are executed.
I'd like to run the tasks minimized so that the normal windows desktop
doesn't get covered up by these tasks.

There is no properties for the .bat file that I can set to run the task
minimized. I tried creating a shortcut for the .bat file which does have a
property tab with a setting for the startup mode. Every time I try to
change my Scheduled task to use the shortcut (.lnk) file, though, it
switches the filename back to the object of the .lnk file (the original
batch file) rather than keeping the .lnk file in the target filename field.

Can anyone suggest a way for me to hide (or at least minimize) these started
tasks?
Hi,


You can e.g. use a vbscript based batch file launcher for this, this
way you can hide the batch file completely.

Run it like this:

wscript.exe "C:\My Scripts\BatchLauncher.vbs" "C:\My Scripts\tst.bat"

(BatchLauncher.vbs is the VBScript, tst.bat is your batch file)

In the code below, it is the 0 in this line that hides the
batch file execution:

iRC = oShell.Run("""" & sFilePath & """", 0, True)

If you want to run it visible, but minimized, change the 0 to 7.


Content of BatchLauncher.vbs:


'--------------------8<----------------------
sTitle = "Batch launcher"

Set oArgs = WScript.Arguments
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

If oArgs.Count <> 1 Then
' Will die after 10 seconds if no one is pressing the OK button
oShell.Popup "Error: You need to supply a file path " _
& "as input parameter!", 10, sTitle, vbCritical + vbSystemModal

Wscript.Quit 1
End If

sFilePath = oArgs(0)

If Not oFSO.FileExists(sFilePath) Then
' Will die after 10 seconds if no one is pressing the OK button
oShell.Popup "Error: Batch file not found", _
10, sTitle, vbCritical + vbSystemModal

Wscript.Quit 1
End If

' add quotes around the path in case of spaces
iRC = oShell.Run("""" & sFilePath & """", 0, True)

' Return with the same errorlevel as the batch file had
Wscript.Quit iRC

'--------------------8<----------------------



WSH 5.6 documentation (local help file) can be downloaded
from here if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp
 
Thanks Torgeir, that did exactly what I wanted. I tried the variations of
the "start" command that others provided, but they all left the DOS box from
the "cmd" execution hanging at the prompt. I tried coding an exit statement
in the batch file, but I believe that only flushes the secondary command
processer the "start" spawns. I tried some of the other start command
parameters, but none of them would close the original cmd box. Your
technique works great though, so thanks once again.

Ken
 
running Scheduled batch files minimized

Insert cmd /C start /min before the program target in the Windows Scheduler job properties.

Add @Exit to the end of the batch file to get the DOS window to close.
 
Summary: how to run a scheduled cmd bat file minimized (solved with solution)

I keep re-googling this thread so decided to post a short summary for me & others :)

prequisite: all your batch files have an exit-command to fnish 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 ment all this to be parameters or not. Answer NO and the task will be saved as you would expect.

Thank you David Lipman, Sept 7th 2005 :)

Peace!

Devvie


~~~ (e-mail address removed) ~~~

Cuisvis hominis est errare, nullius nisi insipientis in errore persevare
——
All spelling mistakes are my own and may only be distributed under the GNU General Public License! – (© 95-1 by Coredump; 2-012 by DevNullius)
 
Last edited:
Help? This isn't working anymore on Windows 8 (x64). Now, I only end with a command prompt blinking... No exit statement received nor do I think the actual scripts are ran.

Anyone experiences with this? :)

Peace!

devnullius
 
I asked the question here too: stackoverflow. com/questions/18881221/windows-8-how-to-start-a-batch-file-minimized-with-task-scheduler-comspec-me

Peace!

devnullius
 
Back
Top