Inno Setup compilation fails with “Required parame

2019-02-21 07:59发布

问题:

I'm a beginner about Inno Setup.
I want create an installer which copy two .exe files and append a value to the PATH environment variable.

Particularly I have to copy two executable files, called pandoc.exe and pandoc-citeproc.exe which are previously changed by me with visual studio developer prompt to don't have problem of Memory with large file conversions.

So I wrote this script with Inno Setup:

[Setup]
AppName=My Program
AppVersion=1.16.0.2
DefaultDirName={pf}\pandocX64

[Files]
Source: "pandoc.exe"; DestDir: "{app}";
Source: "pandoc-citeproc.exe"; DestDir: "{app}";


[Setup]
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{pf}\pandocX64";
Check: NeedsAddPath('{pf}\pandocX64')

[Code]
function NeedsAddPath(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;

So, If I don't use the part of code to update the PATH variable, the installer copy the two executable files in C:\Program Files (x86)\pandocX64, and this is correct.

But I want also append that directory to the PATH system environment variable. I read these threads:

  • How to set a global environment variable from Inno Setup installer?
  • How do I modify the PATH environment variable when running an Inno Setup Installer?

and I tried to write the code above.

Note that I put PATH as ValueName, and {olddata};{pf}\pandocX64 as ValueData to append to the current PATH value the directory in which the executable files are copied.

If I try to run this code, an error on line 17 is displayed

Required parameter "Root" not specified.

I think that Inno Setup expects the Root keyword in the line with code:

ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{pf}\pandocX64";

More precisely, I think that Inno Setup expects something like Inno Setup - Setting Java Environment Variable, but if I use that code, the PATH variable will be set to the {pf}\pandocX64 value, and no append operation will be performed.

Can someone help me?

Thank you

回答1:

When you want to break a section entry to multiple lines for readability, you have to add \ at the end of the lines to escape the new-line character(s). A good practice is also to indent the lines, to make it clear to a human reader.

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{pf}\pandocX64"; \
    Check: NeedsAddPath('{pf}\pandocX64')

Otherwise the Inno Setup compiler treats each line as a separate, and consequently an incomplete, entry.


I've corrected the answer to How do I modify the PATH environment variable when running an Inno Setup Installer? to include the \'s.