在 Inno Setup 中运行 schtask.exe 之前创建带有安装路径的 XML 任务文件 [英] Create XML task file with installation path before running schtask.exe in Inno Setup

查看:38
本文介绍了在 Inno Setup 中运行 schtask.exe 之前创建带有安装路径的 XML 任务文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying create Inno Setup with scheduled task from XML file. The scheduled task is: My Application need to start with user login.

在 Inno Setup 脚本中:

in Inno Setup script:

[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 文件中的此路径?

This works correctly. But I'd like to set the application path in XML file as {app}\MyApp.exe, because user can install it any location. How can I change this path in the XML file in the setup's run time?

推荐答案

使用 /TR 开关,而不是使用 XML 来指定运行路径.

Use the /TR switch, instead of using the XML to specify the path to run.

[Run]
Filename: "schtasks.exe"; \
    Parameters: "/Create /TR ""{app}\MyApp.exe"" /TN AppStart"


如果您出于某种原因坚持使用 XML,则必须即时创建文件.


If you insist on using XML for some reason, you have to create the file on the fly.

[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 或使用 MSXML2.DOMDocument COM 对象(参见 根据用户偏好编辑已安装的 XML 文件在 Inno Setup 中).

You can create the file using simple functions like the SaveStringsToUTF8File or use the MSXML2.DOMDocument COM object (see Edit installed XML file according to user preferences in Inno Setup).

这篇关于在 Inno Setup 中运行 schtask.exe 之前创建带有安装路径的 XML 任务文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆