Inno Setup, spaces and double quote in [Run]

五迷三道 提交于 2019-12-07 06:30:23

问题


I'm trying to schedule a task on Windows, and unfortunately, it doesn't work! The task is created but not correctly.

When I look into task's parameters, it says:

PROGRAM: C:\Program
ARGUMENTS: Files(x86)\AppName\executable.exe

This is how I proceed:

[Run]
Filename: "schtasks.exe"; Parameters: "/create /tn TaskName /sc MINUTE /mo 10 /tr ""{app}\{#MyAppExeName}""";

And I don't know why it doesn't work, doubles quotes should fix the "spaces problem"

Any ideas?


回答1:


This problem is known and is described in this knowledge base article. You will need to enclose the file name between combination of backslash and quotation marks. That article describes:

Cause:

This problem occurs if the path of the scheduled task contains a space. For example, this problem occurs if you create a schedule for the following task by using Schtasks.exe:

 "c:\foldername containing spaces\task.bat"

Workaround:

To work around this problem, enclose the path portion of the task (not including arguments or switches) between backslash (\) and quotation marks (") character combinations, for example \". Enclose the complete path of the task (including arguments or switches) between quotation marks as usual when you create a path or command that contains spaces.

For example, the following example task does not run when you schedule it:

 schtasks /create /tn "my task" /tr "c:\foldername containing spaces\script.bat arguments" /sc once /sd 07/29/2003 /st 10:01

However, when you enclose the path of the task between the backslash and quotation marks character combinations as in the following example, the scheduled task runs successfully:

 schtasks /create /tn "my task" /tr "\"c:\foldername name containing spaces\script.bat\" arguments" /sc once /sd 07/29/2003 /st 10:01

So in your case it could be:

[Run]
Filename: "schtasks.exe"; Parameters: "/create /tn TaskName /sc MINUTE /mo 10 /tr ""\""{app}\{#MyAppExeName}\""";



回答2:


Late to the party, but as mentioned in this SO answer, you could try to simply add single quotes around your /TR parameter, which would result in

Parameters: "/create /tn TaskName /sc MINUTE /mo 10 /tr '"{app}\{#MyAppExeName}"'";

That might be a bit easier than juggling backslashes.



来源:https://stackoverflow.com/questions/23611855/inno-setup-spaces-and-double-quote-in-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!