Inno安装 - 如何在安装开始之前复制文件? [英] Inno Setup - How to copy a file before Setup Start?

查看:965
本文介绍了Inno安装 - 如何在安装开始之前复制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助,我需要复制一个文件到一个文件夹,在inno设置开始之前或之前的选择dir的页面,我想要这个文件从安装程序,而不是从外部源,如果有人复制请给我们一个例子。

i need your help, i need to copy a file to one folder, before inno setup start or before the the page of select dir, i want this file to be copied from the installer and not from an external source, if someone can give an example, please.

我使用这个代码:

  function NextButtonClick1(PageID: Integer): Boolean;
 begin
    Result := True;
    if (PageId = wpWelcome) then begin
        FileCopy(ExpandConstant('file.exe'), ExpandConstant('{reg:HKCU\SOFTWARE\XXX,InstallPath}\file.exe'), false);
    end;
 end;

我希望有人给出一个更好的想法的例子。
从现在开始感谢。

I hope someone give a better idea with an example. Thanks from now on.

推荐答案

要从设置存档中提取文件,以使用 ExtractTemporaryFile 过程。此过程将文件从 [Files] 部分提取到安装应用程序使用的临时目录,您可以在 {tmp} 常数。

To extract a file from the setup archive any time you need you'll have to use ExtractTemporaryFile procedure. This procedure extracts the file from the [Files] section to a temporary directory used by the setup application, which you can find on the path specified by the {tmp} constant. Then you'll just copy such extracted file to a target directory from there by expanding the mentioned constant.

如果你想在安装程序初始化的时候做一些事情,但是,在创建向导表单之前,请使用 InitializeSetup 事件功能。注意,你甚至可以退出该功能的设置,而无需看到向导窗体。如果你要复制的文件是至关重要的。以下是示例代码,但首先查看 已注释的版本 它的一些细节:

If you want to do something when the setup is being initialized, but before the wizard form is created, use the InitializeSetup event function. Note, that you can even exit the setup from that function without seeing the wizard form e.g. if the file you're going to copy is critical that much. Here's a sample code, but first take a look at the commented version of it for some details:

[Code]
function InitializeSetup: Boolean;
begin
  Result := True;
  ExtractTemporaryFile('File.exe');
  if FileCopy(ExpandConstant('{tmp}\File.exe'), 
    ExpandConstant('{reg:HKCU\SOFTWARE\XXX,InstallPath}\File.exe'), False) 
  then
    MsgBox('File copying succeeded!', mbInformation, MB_OK)
  else
    MsgBox('File copying failed!', mbError, MB_OK)  
end;

这篇关于Inno安装 - 如何在安装开始之前复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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