Windows – Start service from Task Scheduler as minimised

command linescheduled-taskswindows

After creating a scheduled task after following this Superuser question, I can successfully start a service without the UAC prompt. The options selected were:

  • Start a program
  • Program\script = C:\Windows\System32\net.exe
  • Add arguments (optional) = start "SERVICE-NAME"

Then in a batch file I call schtasks /run /tn TASK-NAME. After testing this, I created a shortcut to the batch file and set the Run option to Minimised.

This all works except that when the actual service is started, a maximised command prompt window pops up with the single line The SERVICE-NAME service is starting. This then disappears after a few seconds.

How do I tell Task Scheduler to start the target program silently (or minimised) without the pop-up? If the pop-up command prompt were minimised that would be fine.

Best Answer

  • The problem is that when you configure the shortcut to run minimized you launch minimized only the program that starts the scheduled task, not the program that the task executes. You need another piece in your Rube Goldberg machine launch sequence, make the following changes:

    • Program\script = C:\Windows\System32\cmd.exe
    • Add arguments (optional) = /c start /min net start "SERVICE-NAME"

    The first "start" is the cmd.exe start command, which we use for two functions:

    1. Launch net.exe minimized.
    2. Make taskeng.exe finish as soon as net.exe is launched instead of waiting for it to finish.

    Note that this solution is not perfect as taskeng.exe will flash briefly until the net.exe is launched, but usually less than a second.

  • Related Question