Ken Levy wrote:
> 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
--
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/scr...r/default.mspx