Scheduled Task gets removed upon reboot - windows

I'm trying to make a scheduled task for a small software I had written for a friend,
I'm using
Schtasks /create /SC MINUTE /MO 30 /tn JoesInventoryReader /tr C:\joes.exe /RL HIGHEST
But for some reason, whenever we reboot the computer, this task is removed.
I was reading all of Schtasks parameters and none mentioned anything related to automatic removal.
Help? I've been trying to fix that for over an hour.
Thanks in advance everyone

Your task is triggered once and then runs repeatedly.
If you want to execute the program regularly, you should use /SC DAILY (or weekly, monthly) or /SC ONLOGON.
Use /RI to define the repetition and /DU to define the length of the repetition:
Schtasks /create /SC DAILY /RI 30 /DU 24:00 /tn JoesInventoryReader /tr C:\joes.exe /RL HIGHEST

Related

Create a task which will expire/disable after sixmonth from its start date

I want to create a windows task which will run a batch file every day at 12.00am for only six months from the day the task is created. I'm using following command to create a task. I'm not sure how to set expiration date so that the task will stop executing after six months.
My command is:
schtasks /create /sc Daily /mo 10 /tn run /tr "C:\Users\Rashmi\test.bat" /st 00.00
Any help is appreciated.
get the help of Powershell to easily calculate the enddate (it's generaly possible with pure batch, but it's a nightmare):
for /f "delims=" %%a in ('powershell "(get-date).AddMonths(+6).ToString('MM/dd/yyyy')"') do set "enddate=%%a"
schtasks /create /sc Daily /mo 10 /tn run /tr "C:\Users\Rashmi\test.bat" /st 00.00 /ED %enddate%
See here for a pure batch solution and a solution using VBS instead of Powershell (but needs a temporary file).
You want a /ed parameter and to establish the value dynamically using the %date% value
See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks#BKMK_create

How to change start directory of an scheduled task with schtasks.exe in Windows programatically?

I am trying to schedule a task with this command
SCHTASKS /Create /TN MyTaks /SC minute /MO 1 /TR "%cd%\myfile.exe"
I need Task Scheduler run my file inside current directory of myfile.exe.
How this can be done considering that I tested this command also.
SCHTASKS /Create /TN MyTaks /SC minute /MO 1 /TR "\%cd%"%cd%\myfile.exe"
I solved it with adding /V1
SCHTASKS /Create /V1 /TN MyTask /SC minute /MO 1 /TR "%cd%\myfile.exe"

Windows task scheduler run a task from monday to saturday every 5 minutes

I would like to create a Windows task scheduler run a task from monday to saturday every 5 minutes. So far I have only figured out how to run either of them but not combine both criterias.
schtasks /create /tn "LC_GO" /tr "C:\USERS\LK5300\DESKTOP\copyDirectory.bat" /sc minute /mo 5
or
schtasks /create /tn "LC_GO" /tr "C:\USERS\LK5300\DESKTOP\copyDirectory.bat" /SC WEEKLY /D MON,TUE,WED,THU,FRI
could someone please advice how to combine them
Is there any reason for you to not use Task Scheduler UI instead of command line? There's an option to create a weekly recurring event there, then set days on which task should occur and tick option to repeat it every 5 minutes

Windows 7 Scheduled task command line

This command should create a task that every minute runs the calculator windows application.
schtasks /Create /tn "mytask" /sc MINUTE /mo 1 /ru "myuser" /rp "mypassword" /tr "C:\Windows\System32\calc.exe"
It runs OK, the tasks gets added. The task looks right. The tasks shows as started in the schedular but the calculator does not get fired up. The exe exists, I can run it separately.
Anyone know why I don't see the calculator?
How to Create, Modify and Delete Scheduled Tasks from the Command Line
Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.
While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:
Manipulate tasks in batch scripts.
Control and create tasks on networked machines without having to login to them.
Mass create/sync task across multiple machines.
Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.
Eg:
Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:
SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00
Modify ‘My Task’ to run at 2 PM:
SchTasks /Change /TN “My Task” /ST 14:00
Create ‘My Task’ to run C:RunMe.bat on the first of every month:
SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00
Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:
SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00
Delete the task named ‘My Task’:
SchTasks /Delete /TN “My Task”
Probably because the task isn't running interactively. Add the '/it' option:
/IT
A value that enables the task to run interactively only if the
/RU user is currently logged on at the time the task runs. The task
runs only if the user is logged on.
Without the /it option, tasks run in session 0, which doesn't allow interaction with the user. For more information, do a web search for "Session 0 isolation".

My schtasks don't schedule anything. :(

I'm trying to make a scheduled task, and its just not working for me.
This is the command I type in CMD:
schtasks /create /sc minute /mo 1 /tn test /tr calc.exe /st 19:17:00 /sd 12/14/2009
I'm trying to tell the computer to run calculator every minute starting at 7:09 PM. Although I get a success message after I type this in and hit enter, nothing happens at 7:09. What gives?
Thanks in advance.
Thank you popester, for the first time I get run a task using command line parameters. Waffles, my task has been created however, it also didn't run. So I added some parametters and now it works. Try:
schtasks /create /th test2 /tr "c:\temp\run.bat" /sc daily /st 18:10:00 /ru SRVIMG\Administrator /rp XXXXXXX
Where XXXXXXX is my administrator password
/st wants HH:mm, not HH:mm:ss. The following works for me on Windows 7:
schtasks /create /sc minute /mo 1 /tn test /tr calc.exe /st 14:43 /sd 12/15/2009
Doc:
/ST starttime Specifies the start time to run the task. The time
format is HH:mm (24 hour time) for example, 14:30 for
2:30 PM. Defaults to current time if /ST is not
specified. This option is required with /SC ONCE.
make sure that your task scheduler service is running as well. check in your "control panel" under "services"

Resources