High-privilege autorun programs (tasks) stopping on their own

4

2

There’s a program that I want to be automatically run on startup, but because it requires elevated privileges, UAC interferes with it auto-running.

I used the Task Scheduler method of working around this issue; I created a task for it, then created a shortcut to run the task, set it to be minimized, and put it in the Startup folder in the Start Menu.

It works as expected for the most part; the program runs automatically on startup without prompt and minimizes to the tray.

There is however a problem: it seems to disappear now and then, seemingly for no reason. Why‽

(Actually, I have done this for two programs; one disappears and the other creates a crash-dump.)

Synetech

Posted 2013-10-04T17:26:35.323

Reputation: 63 242

Curiously enough, recently when I wanted to configure an autorun admin program in Windows 7, I used the task-method because I had forgotten about the solution I had come up with. I was reminded of it while making this post, and since it does not have the issues that the task-method has, I might switch to that.

– Synetech – 2013-10-04T17:53:01.810

Answers

6

The problem is likely due to default task settings and is more often manifest on laptops.

It turns out that when you create a task, some of the default settings are not the ones you want and will cause problems for auto-run programs, so you must make sure to check all of the settings when using the Task-Scheduler workaround.

In the Settings tab (figure 1), make sure to disable the Stop task if it runs longer than… setting. Leaving this setting (which defaults to three days) would cause the auto-run program to end after a few days, so if you use standby or hibernate instead of shutting down (common with laptops), then you could find the program has stopped running three days after you last booted.

In the Conditions tab (figure 2), make sure to disable all options in the Power section. The default settings cause the program to not be auto-run if you are running on battery while booting. In addition, the default makes it so that even if you are plugged in while booting and the program runs, as soon as you pull out the cord and switch to battery, Windows stops it.

(The Wake the computer to run this task option is disabled by default, and you should leave it as such because an auto-run program would never need this.)

Caveat

One thing to note is that if you turn off the setting Start the only if the computer is on AC power, then it will disable the setting Stop if the computer switches to battery power (figure 3). The obvious implication is that regardless of what the checkbox for the latter setting shows, if you have disabled the former one, then tasks will not end when switching to battery power. This makes sense and pretty much everybody would expect that to be the case, moreover, this is how all properly written programs behave. Unfortunately there is a bug in Windows whereby the Task Scheduler follows the second checkbox irrespective of the first one. Therefore if you disable the first setting but the second one has a check, then switching to battery power will stop the task. To stop this, you must enable the first option, disable the second, then disable the first again.


Figure 1: Default Task Scheduler settings

Task Scheduler default settings

Figure 2: Default Task Scheduler conditions

Task Scheduler default conditions

Figure 3: Task Scheduler battery-power bug that bugged me to no end

Task Scheduler battery-power bug

Synetech

Posted 2013-10-04T17:26:35.323

Reputation: 63 242

battery-power bug that bugged me to no end I was tracking task scheduler history arbitrarily for a few weeks now to figure out why a daemon would stop without reason. Just for reference, this gave it away and led me here: Task Scheduler stopped instance "{...}" of task "\..." because the computer is switching to battery power. Thanks! – Kohányi Róbert – 2019-07-11T16:34:59.103