在 Inno Setup 中运行 schtask.exe 之前,使用安装路径创建 XML 任务文件

2024-01-02

我正在尝试使用 XML 文件中的计划任务创建 Inno Setup。计划任务是:我的应用程序需要以用户登录启动。

在 Inno 安装脚本中:

[Run]
Filename: "schtasks.exe"; 
    \Parameters: "/create /XML ""{app}\Schedule.xml"" /TN AppStart"

in Schedule.xml file:

<Actions Context="Author">
    <Exec>
        <Command>"C:\Program Files\MyApp\MyApp.exe"</Command>
    </Exec>
</Actions>

这工作正常。但我想将 XML 文件中的应用程序路径设置为{app}\MyApp.exe,因为用户可以将其安装在任何位置。如何在安装程序运行时更改 XML 文件中的此路径?


Use the /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 https://jrsoftware.org/ishelp/index.php?topic=isxfunc_savestringstoutf8file或使用MSXML2.DOMDocumentCOM 对象(参见根据 Inno Setup 中的用户首选项编辑已安装的 XML 文件 https://stackoverflow.com/q/39467048/850848).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Inno Setup 中运行 schtask.exe 之前,使用安装路径创建 XML 任务文件 的相关文章

随机推荐