Inno安裝程序無法將文件自行安裝到隨機數目的目標文件夾。
你必須一切帕斯卡爾腳本代碼:
[Files]
Source: "MyFile.dat"; Flags: dontcopy
[Code]
procedure ExtractFileToPathsWhereAnotherFileIs(ExtractFile: string; SearchFile: string);
var
P: Integer;
Paths: string;
Path: string;
TempPath: string;
begin
{ Extract the file to temporary location (there's no other way) }
ExtractTemporaryFile(ExtractFile);
TempPath := ExpandConstant('{tmp}\' + ExtractFile);
Paths := GetEnv('PATH');
{ Iterate paths in PATH environment variable... }
while Paths <> '' do
begin
P := Pos(';', Paths);
if P > 0 then
begin
Path := Trim(Copy(Paths, 1, P - 1));
Paths := Trim(Copy(Paths, P + 1, Length(Paths) - P));
end
else
begin
Path := Trim(Paths);
Paths := '';
end;
{ Is it the path we are interested in? }
if FileExists(AddBackslash(Path) + SearchFile) then
begin
Log(Format('Found "%s" in "%s"', [SearchFile, Path]));
{ Install the file there }
if FileCopy(TempPath, AddBackslash(Path) + ExtractFile, False) then
begin
Log(Format('Installed "%s" to "%s"', [ExtractFile, Path]));
end
else
begin
MsgBox(Format('Failed to install "%s" to "%s"', [ExtractFile, Path]),
mbError, MB_OK);
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ExtractFileToPathsWhereAnotherFileIs('MyFile.dat', 'matlab.exe');
end;
end;