26

I have scheduled a task to be run at system startup. But its not working. When I run the task manually, it is working. Below are the screenshots of the settings.

enter image description here

enter image description here

What have I done wrong here? This task executes a bat file that launches a process. Btw, the result of last execution is shown as successful though.

AnOldSoul
  • 479

12 Answers12

12

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.

toofat
  • 331
3

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?

Esa Jokinen
  • 52,963
  • 3
  • 95
  • 151
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

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

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
Alpha2k
  • 121
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'.

guest
  • 21
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 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.

Steve S.
  • 111
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...

1

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.
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.