How to create task using schtasks.exe with multiple days of month - windows

I try to create this scheduled task using the command line:
I tried:
schtasks.exe /Create /tn test1 /tr notepad.exe /sc montly /m jan,feb /d 12,27
but it seems that /d can get only one parameter, for example: /d 12
How can I create the same task as in the wizard? I want to create a task that runs every 12 and 27 of january and febuary.
Thanks,
Inbal.

The only way I found to do it, is by using xml and pass it as a parameter to the /create command.

Related

Onidle task starting after specific date

I'm trying to create a batch file that will (among other things) create task for Windows Task Scheduler that should be executed every time computer goes idle for some time but should start executing that task only after the specific date.
When I tried to write it like that
schtasks /create /TN "Connection Configuration" /SC onidle /i 5 /sd 12/13/2018 /tr "C:\Program Files\OpenVPN\config\client.bat"
I get the error message telling that /SD parameter can't be used with onidle.
Is there any other way to do that on Windows 10 Pro?
You are missing /create parameter.
This works for me:
schtasks /create /tn test123 /sc onidle /i 1 /sd 09/12/2018 /tr "cmd /c mkdir test123"
/sd can be used but /st cannot.
If this is not enough, export the task as XML, modify it, and then import with
schtasks /create /xml c:\path\to\file.xml /tn INSERT_TASKNAME_HERE

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

scheduling task from the command line + windows7 + spaces + arguments

I am trying to become familliar with add task to task scheduler via the command prompt. I seem to be having difficuly with spaces.
This command works successfully in creating a task:
schtasks /create /tn \Daily\SOTask /tr "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs" /sc daily /mo 1 /st 08:50
SUCCESS: The scheduled task "\Daily\SOTask" has successfully been created.
However, when I open the properties of this task in task scheduler i see in:
Program/script: C:\Users\User
Add arguments(optional): Name\FolerWhereScriptIs\vbsScript.vbs
Start in(optional): empty
this is obviously not what I want. ideally I would like:
Program/script: C:\Windows\System32\WScript.exe
Add arguments(optional): "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs"
Start in(optional): C:\Users\User Name\FolerWhereScriptIs\
How do I achive this from the command line?
This lists all tasks in the Daily folder (so I can see the one I jst created)
schtasks /query /TN Daily\
NOTE: To get this far I ahve gotten help for here and here
EDIT1 I found help here and it mentions using a /V1 flag but todate I cannot get to work. Another Option would be to use XML, whcih I will investigate again. For now I will use the command for setting up my schedule and then go into task scheduler to set the Start in(optional): in directory.

Change the start time of tasks by 1 hour using schtasks.exe

Is it possible to move the start or run time of scheduled tasks in Windows server 2003 machine by 1 hour without hardcoding the time using /ST paramter of schtasks command? I also don't want to use Scheduled Tasks GUI because it is a lengthy process using it for many tasks.
For eg. if task A run at 8 AM and task B at 10 AM, I want to move them to 9 AM and 11 AM respectively. If it's not possible, please suggest better ways of doing it. Thanks in advance!
AFAIK schtasks does not provide a way to change the schedule relative to the existing schedule. You could query the current schedule from the task and then modify it accordingly:
setlocal EnableDelayedExpansion
for /f "tokens=5" %%t in (
'schtasks /query /tn foo /fo list ^| find /i "next run time:"'
) do (
if "%%t"="08:00:00" (
schtasks /change /tn foo /st 09:00
else if "%%t"="10:00:00" (
schtasks /change /tn foo /st 11:00
)
)
Can't be done with schtask.exe
You can't use the /st switch with the /change switch. You'd have to delete and create. But you would risk losing advanced options that you can't see with Schtask.exe. Basically you'll need to look at powershell instead to accomplish what you want.

executing a batch file into a new command window using windows task schedular

I have test_run.bat file to be scheduled to run at specified time and date. I have added this into a task scheduler using following comand:
set testfile=%%~dp0%test_run.bat release
schtasks /create /tn "test_run" /tr "%testfile%" /sc weekly /d * /mo 1 /st %tt% /sd %dd%
here I'm planning to run "test_run.bat" with "release" as an argument to it. When this task starts, it runs in the background. I want this to open a new command window (starting into a folder where this batch file exists) and run this batch file.
How can I achieve this? Are above mentioned two lines correct(considering release as an argument)?
Using start:
set testfile=start /c %%~dp0%test_run.bat release
schtasks /create /tn "test_run" /tr "%testfile%" /sc weekly /d * /mo 1 /st %tt% /sd %dd%
I this correct?
The start command creates a new command window.
At its very simplest, the command
start test.bat
will create a new command window and run the batch file in it.

Resources