Schedule task with spaces in the path

We plan the task programmatically. However, the executable to be scheduled can be installed in the path with spaces. those. c: \ program Files \ folder \ folder \ program \ program.exe folder

When we provide this path as a parameter to the Tasjk scheduler, it will not start because it cannot find the executable. Obviously, it must be enclosed in quotation marks (").

The problem is that even when we put quotes around the path when we pass it as paramemter (cmd + "\" + path + "\"), it still doesn't include quotes in the path used to schedule the task.

Does anyone know how to get quotes to be included in the path?

EDIT: Respond to comment:

We had the same idea and here's the problem. the ~ 1 format is based on the folder index, so if you said you have these 3 folders:

Program Applications
Program Files
Program Zips

      

then the path will be as follows: progra ~ 2

Now, if you say there are more than 10 such folders, the path might look like progr ~ 12.

Now, not to say that this is not a viable solution, but to count the folders to find the correct one and then use the index to build the path is a little cumbersome and not very clean IMO.

We hope there is a better way.

EDIT 2: Added relevant code snippet

You asked for the code: this is how we build the Args string, which 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 your application.

0


source to share


5 answers


You seem to be using schtasks.exe - it took me longer to figure this out than find the answer! More details please! :) I found the answer with a quick google search

Try this code:



string args = "/CREATE /RU SYSTEM /SC " + taskSchedule + " /MO " + taskModifier + " /SD " + taskStartDate + " /ST " + taskStartTime + " /TN " + taskName + " /TR \"\\\"" + taskSource + "\""

      

It adds \ "to the beginning of the TR parameter value.

+2


source


you can replace program files with progra ~ 1
and folder to folder ~ 1 (first 6 letters and ~ 1) to make it work until someone answers correctly.



0


source


Can you show the code?

i.e. make the path in the above example "path" (with quotes) and then call

This might help http://www.jguru.com/faq/viewquestion.jsp?EID=768691

0


source


Guessing the short name is not a good way to do it as it is an implementation detail and may change with every version of Windows.

If you want a short name, just ask it: http://www.c-sharpcorner.com/UploadFile/crajesh1981/RajeshPage103142006044841AM/RajeshPage1.aspx

0


source


Place the batch file in a location that has no spaces.

In a batch file, run program commands with spaces.

-1


source







All Articles