Scheduled *.bat cannot run minimised

G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

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.
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

flahmeshess wrote:

> 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



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

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.
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

flahmeshess wrote:

> 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"


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


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx