0

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.

Community
  • 1
  • 1
HattrickNZ
  • 4,373
  • 15
  • 54
  • 98
  • 1
    You can use single quotes within the command line, with the whole thing including command line arguments (if any) wrapped in double quotes: `/tr "'C:\Windows\System32\WScript.exe' 'C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs'"`. Display it in list mode: `schtasks /query /tn \Daily\SOTask /v /fo list`. – Eryk Sun Jan 23 '15 at 00:03
  • I don't see a way to set the working directory, not without a full XML definition. It may be easier to add a command-line argument to your script that sets the target directory. – Eryk Sun Jan 23 '15 at 00:24
  • @eryksun tks i think you are right I have reflected this in my edit1 above – HattrickNZ Jan 29 '15 at 02:51

0 Answers0