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
Related
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"
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".
I need to set a Windows scheduled task that runs at logon and repeats at a given interval (say hourly for this case).
Basically, I want to do this via command line: https://dl.dropbox.com/u/19514611/Capture.PNG
Microsoft's schtasks.exe page (found here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx) seems to imply you can't set any repetition for an ONLOGON event via command line, but can via the wizard. Is this accurate?
EDIT:
After further research, I've found that I can export this configuration as an XML and build the task using the xml. Is this the way I should go about this? It will require something to parse out and generate a new xml file for each user (less than ideal) and I'd much rather do this via command line.
I realize this thread is old but recently ran into the same issue. The trick is to run a change command after the initial create command. The following will change the task to run every 1 minute.
SCHTASKS.exe /Create /SC ONLOGON /TN "Your Task Name" /TR "c:\path\executableoftask.exe" /RU SomeUser /RP SomePassword
SCHTASKS.exe /Change /RI 1 /TN "Your Task Name" /RU SomeUser /RP SomePassword
SCHTASKS /CREATE /U username /P password /SC ONLOGON /TN "Your Task Name" /TR c:\path\executableoftask.exe /RI HOURLY
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.
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"