How to execute a scheduled task with "schtasks" without opening a new command line window?
I have a batch file that creates a scheduled task using schtasks
like this:
schtasks /create /tn my_task_name
/tr "...\my_path\my_task.bat"
/sc daily
/st 10:00:00
/s \\my_computer_name
/u my_username
/p my_password
It works OK except the fact that when my_task.bat
is executed - a new command line window is opened (and closed after execution).
I would like to avoid opening this new window (i.e. to run the task in quiet mode, in the background).
I thought to use
start /b ...\my_path\my_task.bat
but I don't know how, because since I have to call start
from the batch file I need to precede it with cmd /c
, which again causes the new window to open.
How could I solve this problem ?
Solution 1:
I believe you're seeing the box because the account you set to run it as is your own. Try either of these:
1: Run the task as the user NT Authority\System
2: Make a new account and set the task to run with its credentials
Solution 2:
You can do this by specifying /RU option for schtasks. This option
specifies the user account (user context) under which the task runs. For the system account, valid values are "", "NT AUTHORITY\SYSTEM" or "SYSTEM".
And thus, try this
schtasks /create /tn my_task_name
....
/st 10:00:00
/ru "SYSTEM"
....
Solution 3:
Perhaps using the AT
command and don't include the /interactive
switch.
Example:AT \\my_computer_name 10:00AM /EVERY:M,T,W,Th,F,S,Su "...\my_path\my_task.bat"
If you need specific credentials for my_task.bat to run under, you will pobably have to put RUNAS
in the command because I believe the command will run under the security context of the Schedule (Task Scheduler) service which is the "Local System" account. Adding the RUNAS
command and switches before you BAT file should fix that.