代码之家  ›  专栏  ›  技术社区  ›  Wurlitzer

在Inno安装程序中找到应用程序的路径,并将文件复制到该目录

  •  1
  • Wurlitzer  · 技术社区  · 7 年前

    在Windows命令行中,可以获得MATLAB可执行文件的路径,如下所示:

    where matlab
    

    C:\Program Files (x86)\MATLAB\R2015b\bin\matlab.exe
    

    C:\Program Files (x86)\MATLAB\R2015b\toolbox\local
    

    如何做到这一点?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Martin Prikryl    5 年前

    这个 where PATH

    在Inno Setup Pascal脚本中,可以使用 FileSearch function

    FileSearch('matlab.exe', GetEnv('PATH'))
    


    无论如何,您可以使用上述方法将路径解析为中的全局变量 InitializeSetup event function

    然后您可以使用变量作为安装路径 scripted constant .

    [Files]
    Source: "MyFile.dat"; DestDir: "{code:GetMatlabToolboxLocalPath}"
    
    [Code]
    
    var
      MatlabToolboxLocalPath: string;
    
    function GetMatlabToolboxLocalPath(Param: string): string;
    begin
      Result := MatlabToolboxLocalPath;
    end;
    
    function InitializeSetup(): Boolean;
    var
      MatlabExePath: string;
    begin
      MatlabExePath := FileSearch('matlab.exe', GetEnv('PATH'));
      if MatlabExePath = '' then
      begin
        MsgBox('Cannot find MATLAB', mbError, MB_OK);
        Result := False;
        Exit;
      end;
    
      MatlabToolboxLocalPath := ExtractFilePath(MatlabExePath) + '..\toolbox\local';
    
      Result := True;
    end;