How do I modify the PATH environment variable when running an Inno Setup Installer?

后端 未结 6 607
逝去的感伤
逝去的感伤 2020-11-28 03:31

Inno Setup lets you set environment variables via the [Registry] sections (by setting registry key which correspond to environment variable)

However, sometimes you d

6条回答
  •  借酒劲吻你
    2020-11-28 04:16

    You can use LegRoom.net's modpath.iss script in your InnoSetup script file:

    #define MyTitleName "MyApp" 
    
    [Setup]
    ChangesEnvironment=yes
    
    [CustomMessages]
    AppAddPath=Add application directory to your environmental path (required)
    
    [Files]
    Source: "install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; 
    
    [Icons]
    Name: "{group}\{cm:UninstallProgram,{#MyTitleName}}"; Filename: "{uninstallexe}"; Comment: "Uninstalls {#MyTitleName}"
    Name: "{group}\{#MyTitleName}"; Filename: "{app}\{#MyTitleName}.EXE"; WorkingDir: "{app}"; AppUserModelID: "{#MyTitleName}"; Comment: "Runs {#MyTitleName}"
    Name: "{commondesktop}\{#MyTitleName}"; Filename: "{app}\{#MyTitleName}.EXE"; WorkingDir: "{app}"; AppUserModelID: "{#MyTitleName}"; Comment: "Runs {#MyTitleName}"
    
    [Registry]
    Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"
    
    [Tasks]
    Name: modifypath; Description:{cm:AppAddPath};   
    
    [Code]
    
    const
        ModPathName = 'modifypath';
        ModPathType = 'system';
    
    function ModPathDir(): TArrayOfString;
    begin
        setArrayLength(Result, 1)
        Result[0] := ExpandConstant('{app}');
    end;
    
    #include "modpath.iss"
    

提交回复
热议问题