schtasks command - strange folder/path behaviour - windows

I am currently trying to use the schtasks command to change scheduled tasks on a Windows 2008 server. I have successfully updated a task which resides within the 'top level' folder path under Task Scheduler Library, however when I attempt to edit a scheduled task which resides within a subfolder, schtasks cannot find the task but I cannot see why as schtasks can find the job when I run a query using the same path??
The output below will explain better.
Working
C:\>schtasks /query /TN "\Batch Finalisation Time Test"
Folder: \
TaskName Next Run Time Status
======================================== ====================== ===============
Batch Finalisation Time Test 26/11/2015 19:30:00 Ready
C:\>schtasks /change /ED "30/11/2015" /ET "23:59:59" /TN "\Batch Finalisation Time Test" /ru ""
SUCCESS: The parameters of scheduled task "\Batch Finalisation Time Test" have been changed.
Not Working
C:\>schtasks /query /TN "\Elite Maintenance Jobs\Batch Finalisation Time"
Folder: \Elite Maintenance Jobs
TaskName Next Run Time Status
======================================== ====================== ===============
Batch Finalisation Time 26/11/2015 19:30:00 Ready
C:\>schtasks /change /ED "30/11/2015" /ET "23:59:59" /TN "\Elite Maintenance Jobs\Batch Finalisation Time" /ru ""
ERROR: The specified path is invalid.

I've discovered that this seems to be caused by task configuration (General tab), once the "Configure for:" dropdown was updated to 'Windows 7, Windows Server 2008 R2' the task could then be amended successfully via the schtasks command.

For me, it turned out I also needed to be running as Administrator. This command worked from a normal prompt:
schtasks /query /tn "\Microsoft\Windows\WindowsColorSystem\Calibration Loader"
but a similar command to access a task I created in a new folder which I also created only worked from an elevated prompt.

Related

Tasks in task scheduler not running from cmd

I am using command line to create tasks, run them as well as delete. I am able to create tasks in the scheduler with no issue but when i run it via command line it immediately gets stuck as "queued". But when i go to task scheduler GUI and click "run" the tasks run properly. What could i be doing wrong? I am using windows 10. After running it on cmd it outputs "SUCCESS: Attempted to run the scheduled task "_a"." But still nothing happens unless i go the GUI of task scheduler and run it from there.
Here is a code i tried to schedule notepad:
schtasks /create /ru yanic /sc daily /tn "note" /tr C:\windows\system32\notepad.exe
SCHTASKS /RUN /TN "note

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.

FORCE run a scheduled task?

Sometimes I will do :
SCHTASKS /create /tn "Task Name 123" /XML C:\temp\Task Name 123.xml /F
schtasks /run /tn "Task Name 123"
and the task won't run, it will stay at status "waiting" (not sure what the english term is for that since we're using a French windows...)
If I manually go in the taskschd.msc GUI and right-click - RUN, it will run, but it didn't with the /run command shown above. This somehow confirms the schtasks command versus the right click in GUI don't act the same.
Any idea why? Is there something "pending" that can prevent my task from running , how can I FORCE it to run via command line?

Windows task sceduler command to uncheck "Do not store password.The task will only have access to local resources"

I'm creating a task in windows Task Scheduler via command line using following commmand -
schtasks /Create /SC ONSTART /TN "MyTask" /TR "C:\Program Files (x86)\MyApp\MyApp.exe" /RL HIGHEST /NP
Is there any parameter to schtasks /create to uncheck "do not store password" under "user is logged in or not"?.
Also, is there any parameter to uncheck "Stop task if it runs longer than"
I tried following Microsoft Task Scheduler Reference. But, couldn't get the result needed.
Remove /NP from the command. I can get the desired output.

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

Resources