Unable to start scheduled task after creating it with Schtasks

Discussion in 'Windows Server' started by Flea#, Mar 6, 2008.

  1. Flea#

    Flea# Guest


    I'm using Schtasks to create a scheduled task on a remote server using the
    SYSTEM account to run it. After I create the scheduled task, remote into the
    server, I try and run it and it comes back with status of "Could not start".

    When I view the log, it says "The system cannot find the file specified.".
    The really frustrating problem is I can open the scheduled task, copy the
    path and paste it into the run command and it will launch my executable. So
    the path IS correct! If I delete the task and create it manually, browsing to
    the same executable, it will run just fine! So it seems to be something with
    creating it with Schtasks. Here is my command line: Schtasks /create /sc
    DAILY /tn AMFCollector /tr "C:\Program Files\SF\AMF\AMFCollector.exe" /s
    deviisvm01 /ru System /st 01:00:00

    Any help would be appreciated it.
    Flea#, Mar 6, 2008
    1. Advertisements

  2. Hi,

    Using C:\Progra~1\SF\AMF\AMFCollector.exe works.

    For some reason, it is thinking "C:\Program" is the command, and is passing
    "Files\SF\AMF\AMFCollector.exe" as an argument.

    Ryan Newington, Mar 7, 2008
    1. Advertisements

  3. Actually, just read this in the schtaks help

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

    So the correct command line syntax is

    Schtasks /create /sc DAILY /tn AMFCollector /tr "'C:\Program
    Files\SF\AMF\AMFCollector.exe'" /s deviisvm01 /ru System /st 01:00:00

    Ryan Newington, Mar 7, 2008
  4. Flea#

    Dave Patrick Guest

    You should be using the AT command line scheduler for system account tasks.



    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Dave Patrick, Mar 7, 2008
  5. Hi Dave,


    Schtasks replaces At.exe, a tool included in previous versions of Windows.
    Although At.exe is still included in the Windows Server 2003 family, schtasks
    is the recommended command-line task scheduling tool.


    Ryan Newington, Mar 7, 2008
  6. Flea#

    Flea# Guest

    Hey Ryan,

    Thanks for your reply, I really thought that might fix it up but after
    running that, I still received the same error "Could not start" The system
    cannot find the file specified.

    I did notice one thing though. After I automatically create that task, I
    notice the field for "Start in:" is blank, where as, when I manually create
    the task, the "Start In" field has the path in there. On the task that is
    not working, I tried putting in the path, but it still failed, but I did find
    it interesting to why the start in path was not there when I used Schtask but
    it was there when I manually did it.

    Flea#, Mar 7, 2008
  7. Flea#

    Flea# Guest

    I actually found the solution thanks to another forum
    Turns out the problem was the quotes were being stripped off the file path in
    the 'Run" field. No big deal, just need to escape the quotes out, well, not
    once, twice, or three times but four times later, the quotes will finally
    show up and then the task will run.

    I am using powershell to run this, so I had to escape the quotes out with
    its specific escape character but it looks like this:

    "`"`"`"`"C:\Program Files\SF\AMF\AMFCollector.exe'`"`"`"`""
    Flea#, Mar 7, 2008
  8. Flea#

    Dave Patrick Guest

    Ok, thanks for letting us know.



    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Dave Patrick, Mar 9, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.