Tasks in task scheduler not running from cmd - 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

Related

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?

Run schtask locally using jenkins

I have a task to run a bat file locally to schedule a task to open a website i used jenkins to automate it i used start cmd.exe /c SCHTASKS /CREATE /TN "myftp" /TR %TN% /SC daily /ST 14:48:00 it is creating with local cmd but not jenkins windows
batch shell

schtasks command - strange folder/path behaviour

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.

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.

Resources