29

I have scheduled task configured to run at system startup that is not working. When run manually it works.

The task executes a bat file that launches a process as a local user account with a graphic user interface.

Below are the screenshots of the settings.

image

image

What have I done wrong?

4
  • What is "Kube Watchdog"? Google only finds Kube Studios on BBC Watchdog. What kind of process is it and what it is supposed to do when you launch it at system startup? Commented May 9, 2017 at 7:36
  • It is a process that monitors some of the windows services we have developed. When I run it manually from task scheduler it works fine. Just that system startup is not happening Commented May 9, 2017 at 7:53
  • Try removing the checkmark from "Do not store password" Commented May 9, 2017 at 9:04
  • 1
    It's 2 years later and I haven't been able to find a solution for this. 'Run whether use is logged on or not' apparently doesn't work? Commented Jan 21, 2019 at 22:38

13 Answers 13

13

I struggled a while with the same problem. In my case, the problem was the setting "Start the task only if the computer is on AC power".

5

You are executing this Task with "VM" user privileges. Does "VM" account have "Run as a batch Job" rights?

How are you setting up your scheduled task, through local Task Scheduler or through DC GPO Preferences. What I've noticed is if the task is created through DC GPO Preferences is the same ... task will never execute (no matter what you are executing, VBS, PowerShell, CMD, EXE) if the only trigger is "At startup". I must create my Tasks with two triggers:

  1. At task creation/modification

  2. At startup

Now the task executes correctly every time I restart my computers.

REMARK

  1. This only applies if the Tasks are created through GPO Preferences on the DC side.

  2. This only applies for the trigger "At startup". As far as I have seen, every other trigger works fine.

  3. Be sure not to use "Replace" mode when creating this GPO Preference if you do not want for the Task to execute every time computer refreshes it's GPO's. In "Replace" mode during refresh the Task is being recreated and the trigger is "At task creation/modification". Use "Update" mode instead. Also this is where you see one problem with this workaround ... you can not create the Task in this way that should delete itself once the Computer is no longer part of Domain because those kind of Tasks require the "Replace" mode.

1
  • I found another way to work around Task Scheduler tasks created via GPO using the 'At startup' trigger failing was enabling 'Apply once and do not reapply' under the Common tab - this means you can use Replace. instead of Update. Commented Jun 8, 2023 at 11:00
4

Your program isn't a background script or a service. It is a GUI program that should be run as a user in graphical environment. Therefore you should not launch it as a scheduled task on startup but on user login.

As the program is in your own development, you could revise its design: should it have a background service doing the background operations and separated GUI for configuration / monitoring?

2
  • I can have it on user login as well. But that would mean that I need to have the login credentials of every machine that this is installed. It would be rather nice to have it on startup is what I thought. Besides these, why wouldn't this created task work? I tried simply writing to the file on startup, that too doesn't work Commented May 15, 2017 at 2:32
  • so, what is the way to run GUI on startup? It seems like windows is not able to do it Commented Sep 24, 2024 at 21:06
2

Why don't you run this batch file as a windows service? Is there any particular reason? FYI: http://nssm.cc/usage

3
  • Yes that's a valid question. This process is supposed to launch an application for which the UI should be visible. That's why this has to run as an independent process and not a service Commented May 9, 2017 at 9:44
  • So how can it run a GUI when the computer has only just started and nobody is logged in? Are you sure you don't want to run at user logon instead? Commented May 9, 2017 at 10:17
  • 1
    But still, why is this not working? What I've done Commented May 9, 2017 at 10:33
2

I also have problems with Win 10 task scheduler, and for some reason I have same behaviour as you. Task is marked as successfully executed but the program/script does not run.

In order to solve this, at least it works for me, try placing a shortcut of the script as a startup program in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup.

You can also make this shortcut be runned with highest privileges (Admin). I've found this to work better than task scheduler, at least for my software/scripts. Some of them run with GUI and some without GUI, but both of them run fine under Startup folder.

PD: %APPDATA% is an system variable, the full path should look like the following:

C:\Users\YourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 
2

Is fast boot enabled in the BIOS? Win10 uses restart in a similar fashion to sleep mode if fast boot is enabled, so is not a true 'restart'.

2

Put the script in the startup folder for all users %allusersprofile%\Microsoft\Windows\Start Menu\Programs\Startup you can even make it run as admin if needed be editing the properties of the shortcut

2

I know this is an old post but setting up a small MeLE mini-computer with Windows 11 and tried to start mobile hotspot from a powershell script at system startup, I fumble upon the same problem!!!! And what was even more frustrating was the fact that on a reboot the script will run but not on a cold start. So my workaround was to look for "other events" that occur at bootup and I found those in the System Windows Logs: enter image description here

So all I did is add a trigger on an event and watch for this 566 event: enter image description here

And voilà! Now my Hotstop start on cold start everytime! Hope this help.

2

I have had a similar problems. I thought that I will share my findings. What I found where 2 things that helped me.

  • First I tried to uncheck "Start the task only if the computer is on AC power" as Sebastian Badea gave tips about. That helped until i made a change to the trigger. Then it stopped running.
  • What I found to make it work again, was to change the trigger so its starts on a time thats in the future. I my case for running my task every hour, to set the start to the same day and a time thats in the future. If I do that every time I make a change, It runs. Otherwise it will not run at all.
1

I just had this issue while setting up UI tests on Jenkins slave machine, but with one difference - I'm using the "Run only when user is logged on", so not sure if it makes a difference. I fixed the issue with following steps:

  1. Press Win + R
  2. Type secpol.msc and press Enter - The Local Security Policy manager opens
  3. Go to Security Settings – Local Policies – User Rights Assignment node
  4. Double click Log on as a batch job on the right side
  5. Click Add User or Group…
  6. Select the user and click OK

Taken from this article.

1

I had a similar issue with Windows 11 Task Scheduler. I was trying to configure a task at startup to run a Jenkins Agent on a new PC. I had done this successfully on Windows 11 VMs running on the build server, but this was the first time I was setting up a Dell PC on the network (Small start-up, no on-site IT support).

Symptoms:

  1. The Task status was Ready but it would not run.
  2. The Last Run Result is 0x41303 (The task has not yet run.)
  3. The Last Run Time is 11/30/1999 12:00:00 AM

In 'settings' I had ticked the box for 'Allow task to be run on demand' but I still couldn't run it from the Actions menu in the right-hand side bar.

Debugging

In the 'Actions' right-side menu, I clicked 'Enable All Task History' and then 'Run' for the task.

I had to hit 'refresh' and got the following in the history tab

Error: Launch Failure

Clicking on that gave some more general info:

Task Scheduler failed to start "\jenkins_agent" task for user "[redacted]". Additional Data: Error Value: 2147943726

That led me to: https://stackoverflow.com/questions/44348330/task-scheduler-failed-to-start-additional-data-error-value-2147943726

The answers there gave me the clues I needed to fix it, but in their wisdom stackoverflow admins have closed that question, so I can't update the answer there.

Solution

For some reason the account I was using, despite being admin, and having 'Log on as batch job' privilege too, just wouldn't work.

I changed the user running the task to SYSTEM:

  1. right-click on the task and select 'properties'
  2. in the 'General' tab, 'Security options' group, 'When running the task, use the following user account:' Select the 'Change User or Group...' button. Enter 'SYSTEM' in the dialog and click OK.
  3. Click OK and enter credentials to approve.

Then I added 'SYSTEM' to the list of user who had 'Log on as batch job'.

  1. Go to the Start menu.
  2. Type secpol.msc. and press Enter. The Local Security Policy manager opens.
  3. Go to Security Settings - Local Policies - User Rights Assignment node.
  4. Double click 'Log on as a batch job' on the right side.
  5. Click Add User or Group. Add 'SYSTEM'
  6. Click OK.

After this, I could run the task on demand and the task starts after a system reset. So it fixed the problem for me.

However, I don't know why the user account I set the PC up with would not work. I have a theory it's because I am using a general account I used for the Build server VM's and not one that is an official intranet account. Active Directory something something...

0

When you check 'Run whether user is logged on or not', the context will be different and the windows/programs launched by TaskSheduler or Task will not appear on the screen because it is runned on the background.

0

Change the Trigger from "At system startup" to "At log on of any user".

This should solve it.

There are not enough resources to launch an executable that early on.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.