0

I have to restart a program after waking up the laptop. The trigger is working (https://www.sevenforums.com/general-discussion/308855-using-task-scheduler-restart-program-upon-wake-sleep.html)

Then I have 2 actions:

  1. taskkill /f /im "Silent Option.exe"
  2. start a .bat file which contains:
    @echo off

    timeout 5 > nul

    start /min "" "C:\Program Files (x86)\Silent Option\Silent Option\Silent Option.exe"

The reason Im running a bat, is because if I put start /min "" "blabla.exe" on action 2) , it actually doesnt do anything.

I tried with "start" and the rest as parameters, and the whole start /min "" "blabla.exe" ,but none of them work. I also need to delay the start of the program for at least 3 seconds.

Is there a way to get rid of the .bat?

If not, how could I trigger one task once another task started? Like Task1 to taskkill the .exe and Task2 to start the .exe with the built-in task scheduler delay option?

1 Answer 1

0

In Task Scheduler (TS) 's "Program/script" box you must put an .exe or script, but start is a built-in command to the "cmd" shell, so that's why doesn't work.
To execute in TS an arbitrary .cmd chain of commands, without a .bat file:

  • in "Program/script": cmd
  • in "Add arguments": /c "your .cmd command string"
  • in "Start in": your\working\directory

Is there a way to get rid of the .bat?
If not, how could I trigger one task once another task started? Like Task1 to taskkill the .exe and Task2 to start the .exe with the built-in task scheduler delay option?

Sure. In Task1, as 2nd action, can put command to change Task2, and this would trigger the run of Task2 (with a delay). One little obstacle is that when you try to change something in Task2, at command line, for example:
schtasks /change /tn Task2 /it
(/it means interractive; this is just a dummy change which won't actually change anything in Task2, b/c I assume you will create it with "Run only when user is logged on")
then (contrary to what the doc for "schtask.exe" says!) it will ask the user for the "run as" password...
Which we don't want in your case... So we can circumvent it via input redirection:
schtasks /change /tn Task2 /it < file_with_password.txt.

Now we're ready :

  1. Create Task2, with:
    General: "Run only when user is logged on";
    Trigger to be "At task creation/modification" and "Delay task for:" 5 seconds (your choice);
    Actions: "Program/script" cmd and "Arguments":
    /c " start /min "" "C:\Program Files (x86)\Silent Option\Silent Option\Silent Option.exe" "
  2. Create "pass.txt" file storing your user's pass (the one that Task2 is "run as" by)
  3. Create Task1 where, Ist action is your kill command, and 2nd action is:
    "Program": cmd, "Args": /c "schtasks /change /tn Task2 /it < path\to\pass.txt"

I've tested it on my Windows 7.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .