schtasks doesn't run programs with spaces

Discussion in 'Windows Server' started by Jonathan Miller, Aug 22, 2007.

  1. I need to use the schtasks.exe to create a new scheduled task. One of the
    parameters allows you to specify the filename. The file I want to run is in
    the Program Files folder. I specify the path, the task gets created but will
    not run! The only way to fix it is to open the properties of the task in the
    GUI and add double quotes around the whole path! Is there an escape sequence
    or something I can use in the command line so that the quotes stay on the
    file name?

    Here is what I'm doing:

    schtasks /create /SC DAILY /ST 02:30:00 /TN test /TR "C:\Program
    Files\Test\Test.exe" /RU SYSTEM

    As you can see I have double quotes around the path so that the commandline
    recognizes it as one parameter. However, when the task is created the double
    quotes are stripped off the filename stored with the task. Then when I try
    to run the task it won't run because it needed those double quotes. Any
    suggestions would be appreciated here.
     
    Jonathan Miller, Aug 22, 2007
    #1
    1. Advertisements

  2. Jonathan Miller

    SBS Rocker Guest

    Take your command line and insert it into a text file and save it as a .bat
    file. Use the Task Scheduler to run the bat file.
     
    SBS Rocker, Aug 22, 2007
    #2
    1. Advertisements

  3. You basically gave the answer yourself: Add more quotes to compensate
    for the stripped ones.
    schtasks /create /SC DAILY /ST 02:30:00 /TN test /TR """"C:\Program
    Files\Test\Test.exe"""" /RU SYSTEM
     
    Pegasus \(MVP\), Aug 22, 2007
    #3
  4. So it takes four sets of quotes?!? I tried 2 and even 3, but not four.
    Thanks!
     
    Jonathan Miller, Aug 23, 2007
    #4
  5. Okay! The four sets of quotes worked. Now the problem I have is putting
    parameters in there. There parameters can't be inside of the quotes that
    show up in the schedule task. However, they do need to be contained in
    quotes in the command-line so it knows that it all goes together. All of my
    attempts have failed so far. Any ideas?
     
    Jonathan Miller, Aug 23, 2007
    #5
  6. Hello Jonathan Miller webmaster at accs dot net,

    Did you try to change it like:

    schtasks /create /RU SYSTEM /SC DAILY /ST 02:30:00 /TN test /TR """"C:\Program
    Files\Test\Test.exe""""

    Best regards

    Meinolf Weber (Myweb)
    Disclaimer: This posting is provided "AS IS" with no warranties, and confers
    no rights.
     
    Meinolf Weber (Myweb), Aug 24, 2007
    #6
  7. Yes I did. That works great if you don't want to pass any parameters to the
    program you are running with the scheduled task. So if my test.exe requires
    a /input=test.txt paramter it doesn't work.
     
    Jonathan Miller, Aug 24, 2007
    #7
  8. Hello Jonathan Miller webmaster at accs dot net,

    Ok, but the /RU system is used from schtasks not from your test.exe So the
    parameter for test.eex has to be specified also in the quotes for me.

    Best regards

    Meinolf Weber (Myweb)
    Disclaimer: This posting is provided "AS IS" with no warranties, and confers
    no rights.
     
    Meinolf Weber (Myweb), Aug 25, 2007
    #8
    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.