We are scheduling a task programatically. However, the executable to be scheduled could be installed in a path that has spaces. ie c:\program Files\folder\folder\folder program\program.exe
When we provide this path as a parameter to the Tasjk Scheduler it fails to start because it cannot find the executable. It obviously needs to be enclosed in quotes (").
The problem we are having is that even when we enclosed the path in quotes when we pass it as a paramemter (cmd + "\" + path + "\") it still doesnt include the quotes in the path that is used to schedule the task.
Anyone have any idea how to force the quotes to be included in the path?
EDIT: Answer to comment:
We had the same idea, and here is the problem. the ~1 format is based on the index of the folder, so if say you had these 3 folders:
Program Applications
Program Files
Program Zips
then the path would be: progra~2
Now if you say there are over 10 of those folders, the path could possibly look like: progr~12.
Now, not to say this is not a viable solution, but having to count the folders to find the right one and then use the index to build the path is a little cumbersome and not very clean IMO.
We are hoping there is a better way.
EDIT 2: Added applicable code snippet
You asked for the code: this is how we build the Args string that we pass to the scheduler:
string args = "/CREATE /RU SYSTEM /SC " + taskSchedule + " /MO " + taskModifier + " /SD " + taskStartDate + " /ST " + taskStartTime + " /TN " + taskName + " /TR \"" + taskSource + "\"";
where taskSource is the path to the application.