路径中带有空格的计划任务

发布于 2024-07-09 23:52:05 字数 973 浏览 6 评论 0原文

我们正在以编程方式安排任务。 但是,要调度的可执行文件可以安装在有空格的路径中。 即 c:\program Files\folder\folder\folder program\program.exe

当我们将此路径作为参数提供给 Tasjk Scheduler 时,它无法启动,因为它找不到可执行文件。 显然需要用引号 (") 括起来。

我们遇到的问题是,即使当我们将路径作为参数传递时 (cmd + "\" + path + "\"),它仍然不会用引号引起来在用于安排任务的路径中包含引号。

任何人都知道如何强制将引号包含在路径中?

编辑:评论的答案:

我们有相同的想法,并且问题在于 ~1 格式基于文件夹的索引,因此如果假设您有这 3 个文件夹:

Program Applications
Program Files
Program Zips

那么路径将为: progra~2

现在,如果您说这些文件夹中有超过 10 个,则路径 为可能看起来像:progr~12。

现在,并不是说这不是一个可行的解决方案,但必须计算文件夹数量才能找到正确的文件夹,然后使用索引来构建路径,这在我看来有点麻烦而且不是很干净。 我们希望

有更好的方法

编辑2:添加了适用的代码片段

您要求提供代码:这就是我们构建传递给调度程序的Args字符串的方式:

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

其中taskSource是路径。到应用程序。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

罗罗贝儿 2024-07-16 23:52:05

看来您正在使用 schtasks.exe - 我花了更长的时间才弄清楚这一点,而不是找到答案! 请提供更多详细信息! :) 我通过快速谷歌搜索找到了答案

,试试这个代码:

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

它在前面添加了一个 \" TR 参数值。

It appears that you're using schtasks.exe - it took me longer to figure that out than to find an answer! More details please! :) I found an 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's adding a \" to the front of the TR parameter value.

你可以用 progra~1 替换程序文件
并将程序文件夹到文件夹〜1(第一个6个字母和〜1)以使其正常工作,直到有人发布正确答案

you could replace program files with progra~1
and folder program to folder~1 (1st 6 letters and ~1) to get it to work till someone posts the right answer

淡淡離愁欲言轉身 2024-07-16 23:52:05

你能显示代码吗?

即使上面示例中的路径为“path”(带引号),然后进行调用

这也可能有帮助
http://www.jguru.com/faq/viewquestion.jsp?EID= 768691

can you show the code?

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

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

夜访吸血鬼 2024-07-16 23:52:05

猜测短名称并不是一个好方法,因为它是一个实现细节,并且可能随每个 Windows 版本而变化。

如果您需要短名称,只需询问:http:// www.c-sharpcorner.com/UploadFile/crajesh1981/RajeshPage103142006044841AM/RajeshPage1.aspx

Guessing the short name is not a good way since it's an implementation detail and can change with every windows version.

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

糖果控 2024-07-16 23:52:05

将批处理文件放在没有空格的位置。

在批处理文件中,运行带有空格的程序命令。

Put a batch file in a location that does not have spaces.

In the batch file, run the program commands that have spaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文