在 Inno Setup 中创建 XML 安装路径在 运行 schtask.exe 之前的任务文件
Create XML task file with installation path before running schtask.exe in Inno Setup
我正在尝试使用 XML 文件中的计划任务创建 Inno Setup。计划任务是:我的应用程序需要从用户登录开始。
在 Inno Setup 脚本中:
[Run]
Filename: "schtasks.exe";
\Parameters: "/create /XML ""{app}\Schedule.xml"" /TN AppStart"
在 Schedule.xml
文件中:
<Actions Context="Author">
<Exec>
<Command>"C:\Program Files\MyApp\MyApp.exe"</Command>
</Exec>
</Actions>
这工作正常。但是我想将 XML 文件中的应用程序路径设置为 {app}\MyApp.exe
,因为用户可以将它安装在任何位置。如何在设置的 运行 时间内更改 XML 文件中的此路径?
使用 /TR
开关,而不是使用 XML 来指定 运行 的路径。
[Run]
Filename: "schtasks.exe"; \
Parameters: "/Create /TR ""{app}\MyApp.exe"" /TN AppStart"
如果您出于某种原因坚持使用 XML,则必须即时创建文件。
[Run]
Filename: "schtasks.exe"; \
Parameters: "/Create /XML ""{tmp}\Schedule.xml"""; \
BeforeInstall: CreateScheduleXML
[Code]
procedure CreateScheduleXML;
var
FileName: string;
AppPath: string;
begin
FileName := ExpandConstant('{tmp}\Schedule.xml');
AppPath := ExpandConstant('{app}\MyApp.exe');
{ Create file here }
end;
您可以使用 SaveStringsToUTF8File
or use the MSXML2.DOMDocument
COM object (see ) 等简单函数创建文件。
我正在尝试使用 XML 文件中的计划任务创建 Inno Setup。计划任务是:我的应用程序需要从用户登录开始。
在 Inno Setup 脚本中:
[Run]
Filename: "schtasks.exe";
\Parameters: "/create /XML ""{app}\Schedule.xml"" /TN AppStart"
在 Schedule.xml
文件中:
<Actions Context="Author">
<Exec>
<Command>"C:\Program Files\MyApp\MyApp.exe"</Command>
</Exec>
</Actions>
这工作正常。但是我想将 XML 文件中的应用程序路径设置为 {app}\MyApp.exe
,因为用户可以将它安装在任何位置。如何在设置的 运行 时间内更改 XML 文件中的此路径?
使用 /TR
开关,而不是使用 XML 来指定 运行 的路径。
[Run]
Filename: "schtasks.exe"; \
Parameters: "/Create /TR ""{app}\MyApp.exe"" /TN AppStart"
如果您出于某种原因坚持使用 XML,则必须即时创建文件。
[Run]
Filename: "schtasks.exe"; \
Parameters: "/Create /XML ""{tmp}\Schedule.xml"""; \
BeforeInstall: CreateScheduleXML
[Code]
procedure CreateScheduleXML;
var
FileName: string;
AppPath: string;
begin
FileName := ExpandConstant('{tmp}\Schedule.xml');
AppPath := ExpandConstant('{app}\MyApp.exe');
{ Create file here }
end;
您可以使用 SaveStringsToUTF8File
or use the MSXML2.DOMDocument
COM object (see