Windows 7 Scheduled task command line - windows

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".

Related

Scheduled Task gets removed upon reboot

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

How to update a Windows Task Scheduler task from an updater/script running as admin

I'm writing an updater for my application and want to change my "Windows Task Scheduler" task configured by:
schtasks /create /sc once /tn my_task /tr MyApp.exe /rl highest /st 00:00
The updater is running "with highest privileges" and I mainly want to change the path of MyApp.exe.
I've tried:
schtasks /Change /tn my_task /tr MyUpdatedApp.exe (But it asks: Please enter the run as password for... even though the script already runs as admin. And so is not user friendly or even working in my scripted update.)
A powershell script using Get-/Set-ScheduledJob (But it says: A scheduled job definition with Name my_task could not be found. The help text even states Although jobs that are created by using the Register-ScheduledJob cmdlet appear in Task Scheduler, Get-ScheduledJob gets only scheduled jobs. It does not get scheduled tasks created in Task Scheduler.)
How can I updated my scheduled task from my updater/script without user interaction?
I've resorted to exporting and recreating the task using an XML file with the following command:
schtasks /create /f /tn my_task /xml C:\somewhere\my_task.xml
I create the my_task.xml file by exporting it by hand in the GUI and storing it as part of my application.

scheduled task onlogon repeat

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

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"

how to schedule a non-hidden task with schtasks?

I've been trying to create a scheduled task from the command prompt. The task is created, but it runs hidden. Is there any way of running it in a non-hidden way? The process is very long and I would like to see what is going on...
I'm running it on a Vista, but the task is meant to run on pre-vista OS as well...
SCHTASKS /Create /RU \"NT AUTHORITY\SYSTEM\" /SC DAILY /ST 00:00 /TN Backup /TR \"C:\Sis\Backup\Backup.vbs\" /F /V1
Tks,
Filipe Scur
Running as NT AUTHORITY\SYSTEM means it is a system task and will run hidden.
Try run as a different username.

Resources