Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Terminal: Schedule a program with main method arguments

Terminal: Schedule a program with main method arguments

Scheduled Pinned Locked Moved Windows API
helpquestion
5 Posts 3 Posters 40 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mc_Topaz
    wrote on last edited by
    #1

    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?

    Richard Andrew x64R 1 Reply Last reply
    0
    • M Mc_Topaz

      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?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        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.

        M Offline
        M Offline
        Mc_Topaz
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • M Mc_Topaz

          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.

          G Offline
          G Offline
          Graham Breach
          wrote on last edited by
          #4

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

          M 1 Reply Last reply
          0
          • G Graham Breach

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

            M Offline
            M Offline
            Mc_Topaz
            wrote on last edited by
            #5

            Ah... what a simple solution. Thank you VERY much!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups