How do I set a Windows scheduled task to run in the background? [closed]
Asked Answered
M

2

170

Does anyone know how to set a scheduled task to run in background using Windows Task Scheduler?
There doesn't seem to be any option to do this.

Miraflores answered 4/7, 2011 at 7:53 Comment(3)
@AlexS - check this oneRosinarosinante
Maybe will help somebody: howtogeek.com/tips/…Iron
If you are running PowerShell script, here is the solution superuser.com/a/1038142/106079Karlkarla
M
243

As noted by Mattias Nordqvist in the comments below, you can also select the radio button option "Run whether user is logged on or not". When saving the task, you will be prompted once for the user password. bambams noted that this wouldn't grant System permissions to the process, and also seems to hide the command window.


It's not an obvious solution, but to make a Scheduled Task run in the background, change the User running the task to "SYSTEM", and nothing will appear on your screen.

enter image description here

enter image description here

enter image description here

Miraflores answered 4/7, 2011 at 8:3 Comment(13)
So basically it's »Either I see something on my screen or the application gets beyond-administrator privileges«? Doesn't sound too good ...Standard
+1 Solved my problem, thanks! But why does the user account being used have anything to do with the visibility of the window, and why does the "Hidden" checkbox, which sounds like it should do this, not do anything?Plosive
Yeah, while this is a good tip, it's a bad solution. The task ends up running with system priveleges, can intentionally or unintentionally do harm. If it accesses the internet someone may compromise your system. It runs with different user profile so %USERPROFILE% will resolve to a different place. It won't see your documents (unless you hardcode paths). Files it creates may be unaccessible to you (unless you also switch to admin).Cockrell
In case anyone else comes across this. I found this solution on serverfault which doesn't require escalating privileges. serverfault.com/questions/9038/…Lewak
There is another way of doing this with another possibly more acceptable side-effect. Just check the "Run whether user is logged on or not" checkbox. This will run the program in the background. You'll have to provide the user password once when clicking ok though.Heywood
thanks, the best solution. Note: you need to put "SYSTEM" in your language, in my case is Portuguese: SISTEMAEquilibrate
why does the "Hidden" checkbox, which sounds like it should do this, not do anything @JoshuaFrank, that checkbox does not run the program hidden, it hides the task in the Task Scheduler. You can toggle showing hidden tasks on and off via View→Show Hidden Tasks. This is (probably) a way to reduce clutter in the scheduler.Spectacles
@MattiasNordqvist - this doesn't appear to work for non-basic triggers, such as "Whenever any user unlocks the PC" - changing to SYSTEM was necessary in this caseDiplomate
wow. scary part of this is I was able to get a script to run as system user but didn't even have to run the scheduler as admin to do it. wtf. Did I miss something or is this a security flaw bigtime?Loner
Agree with @bambams. Also, there is no need to provide the user password. Just use the appropriate checkbox ("Do not store user password").Fruitage
I found I couldn't use the "Run whether user is logged in or not" as I was trying to use robocopy to my OneDrive online drive and it wouldn't work. Running a SYSTEM did. Since it's just a simple copy, I'm okay with that (I think).Observer
This doesn't work when the task was created with a domain user since there is no SYSTEM object.Upgrowth
Thank you for this hint. I was able to start the Jenkins Agent this way. Using my domain user had caused the CMD app to close after being started.Animadvert
F
9

Assuming the application you are attempting to run in the background is CLI based, you can try calling the scheduled jobs using Hidden Start

Also see: http://www.howtogeek.com/howto/windows/hide-flashing-command-line-and-batch-file-windows-on-startup/

Fascist answered 4/7, 2011 at 8:1 Comment(8)
There is no need to download a new program, Windows comes with one already. It's called start /bFlatfooted
The problem with start is that its a command not a program, so you cannot use it in Task Scheduler.Colemancolemanite
cmd.exe /c start does the trick for commands which are not programs.Gower
@Gower ...which, in turn, leads to a command prompt showing while the task is running. :)Towage
@hypersw, Cammille is correct, the system still creates a console window for the cmd process and the start command, so you still end up with a console window which at the very least flashes for a moment. It just defers the problem (and adds an extra and unnecessary level of abstraction to the issue.Spectacles
@Spectacles you can hide the cmd window by using vbs. Set objShell = CreateObject("WScript.Shell") objShell.Run "your command", 0Dosia
@Dosia , I am new to windows schtasks. I created a task that wakes up every minute and checks if four of my important .exe s are still running and if not start that exe again. This scheduled task works but it flashes the shell for a moment every minute. How do I stop that? How do I use Set objShell = CreateObject("WScript.Shell") objShell.Run "your command", 0 in schtasks create command? ThanksYesima
For me, cmd.exe /C <name_of_non-exe_to_run>, such as CMD file, does the trick for commands which are not programs. Task Scheduler moves /C <name_of_non-exe_to_run> to the arguments for cmd.exe.Valtin

© 2022 - 2024 — McMap. All rights reserved.