Terminal: Schedule a program with main method arguments
-
I would like to run a program with the Windows Scheduler. I can create the task with the GUI in the Task Scheduler (taskschd.msc) but would prefer to create the task by the terminal with the schtasks command. The problem is that my program need one argument for the main method and I'm unable to create a task and specify the argument in the command. In the Windows Scheduler I can specify the argument with no problem. But as I said, I would prefer to create the task in the terminal. I can have notepad started each minute with this command:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr notepad /st 16:03
Starting notepad from the terminal and opening an existing file with this command:
notepad "C:\ProgramData\Test\hello there.txt"
So I "thought" I could combine them:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr notepad "C:\ProgramData\Test\hello there.txt" /st 16:03
Unfortunately that didn't work. I get an error message saying that C:\ProgramData\Test\hello there.txt is an invalid argument. Any solutions?
-
I would like to run a program with the Windows Scheduler. I can create the task with the GUI in the Task Scheduler (taskschd.msc) but would prefer to create the task by the terminal with the schtasks command. The problem is that my program need one argument for the main method and I'm unable to create a task and specify the argument in the command. In the Windows Scheduler I can specify the argument with no problem. But as I said, I would prefer to create the task in the terminal. I can have notepad started each minute with this command:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr notepad /st 16:03
Starting notepad from the terminal and opening an existing file with this command:
notepad "C:\ProgramData\Test\hello there.txt"
So I "thought" I could combine them:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr notepad "C:\ProgramData\Test\hello there.txt" /st 16:03
Unfortunately that didn't work. I get an error message saying that C:\ProgramData\Test\hello there.txt is an invalid argument. Any solutions?
You could try putting the filename as the task command line. This way, if it calls ShellExecute to create the task, it will automatically open in Notepad. Like so:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr "C:\ProgramData\Test\hello there.txt" /st 16:03
The difficult we do right away... ...the impossible takes slightly longer.
-
You could try putting the filename as the task command line. This way, if it calls ShellExecute to create the task, it will automatically open in Notepad. Like so:
schtasks /create /sc minute /mo 1 /tn "RunNotepad" /tr "C:\ProgramData\Test\hello there.txt" /st 16:03
The difficult we do right away... ...the impossible takes slightly longer.
Thanks! That is a smart work-around! I now see I also led you into the wrong way by giving you a false example. Stupid of me. What I actual want to do is start my own application where the application need a file path as argument. Like this:
schtasks /create /sc minute /mo 1 /tn "MyApplication" /tr "C:\ProgramData\Test\MyApplication.exe" "C:\ProgramData\Test\hello there.txt" /st 16:03
That don't work and that is my problem.
-
Thanks! That is a smart work-around! I now see I also led you into the wrong way by giving you a false example. Stupid of me. What I actual want to do is start my own application where the application need a file path as argument. Like this:
schtasks /create /sc minute /mo 1 /tn "MyApplication" /tr "C:\ProgramData\Test\MyApplication.exe" "C:\ProgramData\Test\hello there.txt" /st 16:03
That don't work and that is my problem.
Trying "
schtasks /create /?
" gave me this example:Quote:
==> Spaces in file paths can be used by using two sets of quotes, one set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD need to be double quotes; the inner quotes can be single quotes or escaped double quotes: SCHTASKS /Create /tr "'c:\program files\internet explorer\iexplorer.exe' \"c:\log data\today.xml\"" ...
I tested it with notepad and a file on my desktop and it worked:
schtasks /create /sc minute /mo 2 /tn "RunNotepad" /tr "notepad 'C:\users\graham\desktop\notes.txt'"
-
Trying "
schtasks /create /?
" gave me this example:Quote:
==> Spaces in file paths can be used by using two sets of quotes, one set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD need to be double quotes; the inner quotes can be single quotes or escaped double quotes: SCHTASKS /Create /tr "'c:\program files\internet explorer\iexplorer.exe' \"c:\log data\today.xml\"" ...
I tested it with notepad and a file on my desktop and it worked:
schtasks /create /sc minute /mo 2 /tn "RunNotepad" /tr "notepad 'C:\users\graham\desktop\notes.txt'"