development:inno:add_path_to_reg

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


development:inno:add_path_to_reg [2019/10/31 09:04] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Add {app} to path environment variable in registry ======
 +If your installation contains applications that need to be available from anywhere in Windows, and don't wish to create shortcuts, appending {app} variable value to the Windows PATH variable will do the trick.
  
 +Add this to the [Code] section in your script:
 +For adding {app} to all users path variable
 +<code pascal>
 +function NeedsAddPathHKLM(Param: string): boolean;
 +var
 +OrigPath: string;
 +begin
 +if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
 +'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
 +'Path', OrigPath)
 +then begin
 +Result := True;
 +exit;
 +end;
 +// look for the path with leading and trailing semicolon
 +// Pos() returns 0 if not found
 +Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
 +end;
 +</code>
 +For adding {app} to current user path variable
 +<code pascal>
 +function NeedsAddPathHKCU(Param: string): boolean;
 +var
 +OrigPath: string;
 +begin
 +if not RegQueryStringValue(HKEY_CURRENT_USER,
 +'Environment',
 +'Path', OrigPath)
 +then begin
 +Result := True;
 +exit;
 +end;
 +// look for the path with leading and trailing semicolon
 +// Pos() returns 0 if not found
 +Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
 +end;
 +</code>
 +In order to use the code, add this to the [Registry] section in your script:
 +<code pascal>
 +Root: "HKLM"; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; Check: NeedsAddPath(ExpandConstant('{app}'))
 +Root: "HKCU"; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; Check: NeedsAddPath1(ExpandConstant('{app}'))
 +</code>