Innosetup - reference a file from [Code] before the installation starts

冷暖自知 提交于 2019-12-24 01:36:07

问题


This is sort of a continuation of this question. I have a file that I want to include with my installation package (a .CHM help file) that I need to access during installation from code. It doesn't need to be installed to the user's machine. So I want to
- include the file in the installation package, probably uncompressed (so I guess I will do that with a [Files] ... external flag).
- reference the file during installation with code like:

procedure HelpButtonOnClick (Sender: TObject) ;   
var
    ErrorCode : Integer ;

begin
ShellExecAsOriginalUser ('open', ExpandConstant ('{???}') +  '\MyHelp.chm', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end ;

So can I reference the file before installation starts - i.e. before any files are copied to the user machine? How do I specify the path ExpandConstant ('{???}') to the file? I have a help button on the wizard form that calls the above handler.


回答1:


This is easy. Just do

[Files]
Source: "MyHelp.chm"; Flags: dontcopy

[Code]

procedure HelpButtonOnClick(Sender: TObject);
var
  ErrorCode: integer;
begin
  ExtractTemporaryFile('MyHelp.chm');
  ShellExecAsOriginalUser('', ExpandConstant('{tmp}\MyHelp.chm'), '', '',
    SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;


来源:https://stackoverflow.com/questions/6022588/innosetup-reference-a-file-from-code-before-the-installation-starts

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