Monday, October 14, 2013

Schtasks.exe with programs / script having spaces

When you use the Schtasks.exe command line tool to create a schedule for a task, the task does not run if the path of the scheduled task contains a space. For example, if you create a daily schedule for Chrome opening a web page as the following:
schtasks /create /tn "your task name" /tr "%programfiles(x86)%\Google\Chrome\Application\chrome http://www.awebsite.com/apage" /sc daily /st 12:01

In the example above, Schtasks.exe treats everything after the first space in the path as a command-line argument.

So we should apply a workaround like below:
schtasks /create /tn "your task name" /tr "\"%programfiles(x86)%\Google\Chrome\Application\chrome\" http://www.awebsite.com/apage" /sc daily /st 12:01

In which we add \" before and after the path of the program / script.

In the case you want to make the task  "Run whether user is logged or not", you can add option /ru "System" as the following:
schtasks /create /tn "your task name" /tr "\"%programfiles(x86)%\Google\Chrome\Application\chrome\" http://www.awebsite.com/apage" /ru "System" /sc daily /st 12:01

That's all. Nice day.
Subscribe to RSS Feed Follow me on Twitter!