batch-filescheduled-taskssilent

Problem using Task Scheduler to run batch file silently


I have a scheduled task, which runs a batch file every 3 minutes. This batch file checks the running task list, looking for a certain running task. If the task is running, the batch file exits. If the task is not running, the batch file calls another batch file which starts the task.

This all works fine, but the annoyance of the batch file popping up every three minutes is too much to bear.

So my plan was to start the first batch file silently, by changing the scheduled task to 'Run whether user is logged on or not'. This worked in removing the annoying batch pop up, but has had the undesired effect of also starting the second batch file silently, which in turn starts the task silently, resulting in me not having the console window of the program. (the task is starting fine, just hidden, with no way of accessing the window to view what the program is doing)

Is there a way of making just the initial batch file run silently, but then if it needs to run the second batch file, that file will open normally, in turn allowing the task to open with a console window to view?


Solution

  • Probably you want something like this:
    check_task.bat (this will run silently every 3 min via Task Scheduler):

    @echo off
    tasklist /FI "IMAGENAME eq YourProgram.exe" | find /I "YourProgram.exe" >nul
    if errorlevel 1 (
        schtasks /run /tn "VisibleTaskLauncher"
    )
    exit
    

    start_program.bat (this runs your actual program):

    @echo off
    start "" "C:\Somewhere\YourProgram.exe"
    

    Then Create 2 Scheduled Tasks:

    Task 1: SilentChecker

    Task 2: VisibleTaskLauncher