Scheduled *.bat cannot run minimised

F

flahmeshess

I have written a batch and I want to schedule it to run every half
hour. However, I can't seem to get it to run minimised. It keeps
poping up a black windows (the command prompt style).

Can this be done ?

Thanks.
 
T

Torgeir Bakken \(MVP\)

flahmeshess said:
I have written a batch and I want to schedule it to run every half
hour. However, I can't seem to get it to run minimised. It keeps
poping up a black windows (the command prompt style).

Can this be done ?

Thanks.
Hi,

Something like this maybe in the scheduled task:
cmd.exe /c START /MIN C:\TEST\ACTUAL.BAT


Or 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\BatchLaunher.vbs" "C:\My Scripts\tst.bat"


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 BatchLaunher.vbs:

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

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

If oArgs.Count <> 1 Then
MsgBox "Error: You need to supply a file path " _
& "as input parameter!", vbCritical + vbSystemModal, sTitle
Wscript.Quit 1
End If

sFilePath = oArgs(0)

If Not oFSO.FileExists(sFilePath) Then
MsgBox "Error: Batch file not found", vbCritical + vbSystemModal, sTitle
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
 
F

flahmeshess

I don't know how to do VB Script.

For the cmd.exe approach, there are programs started. The start will
start minimised but the cmd.exe program is started in a window.
 
T

Torgeir Bakken \(MVP\)

flahmeshess said:
I don't know how to do VB Script.

It's pretty easy, really. Put the code I posted e.g. into a Notepad
document and save it as BatchLauncher.vbs (I see that I called it
BatchLaunher in my first post, but I meant BatchLauncher). Be sure
the file ends up with a .vbs file extension and not .txt.

Verify that the .vbs file works by double-clicking on it from Explorer.
You should then get an error message that says "Error: You need to
supply a file path as input parameter!"

In your scheduled task, use this command line (adjust paths to your
real names/paths for the vbscript and batch file):

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

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