Ben Jost
Ben Jost

Reputation: 329

Use "Program Files" directory on both 32-bit/64-bit systems with Inno Setup {pf}

The constant {pf} is the directory of

C:\Program Files

for 32-bit systems and

C:\Program Files (x86)

for 64-bit systems.

However I want to use the directory

C:\Program Files

for both, 32 and 64-bit systems. How can I achieve this?

Upvotes: 11

Views: 13221

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202088

Use a scripted constant like:

[Setup]
DefaultDirName={code:GetProgramFiles}\My Program
[Code]

function GetProgramFiles(Param: string): string;
begin
  if IsWin64 then Result := ExpandConstant('{commonpf64}')
    else Result := ExpandConstant('{commonpf32}')
end;

Though this approach should only be used, if you generate binaries for the respective platform on the fly. Like in your case, if understand correctly, you compile the Java binaries for the respective architecture.


You can also use 64-bit install mode.

Then you can simply use {autopf} constant (previously {pf}):

[Setup]
DefaultDirName={autopf}\My Program

If you have a separate 32-bit and 64-bit binaries in the installer, use a script like:

[Files]
Source: "MyDll32.dll"; DestDir: "{pf32}\My Program"; Check: not IsWin64
Source: "MyDll64.dll"; DestDir: "{pf64}\My Program"; Check: IsWin64

See also:

Upvotes: 17

Airs
Airs

Reputation: 2202

If you are using a single installer for both 64 and 32 bit installs then you should be using the ArchitecturesInstallIn64BitMode Setup Directive. This will change {pf} and other scripted constants to be their 64 bit version when installing on a 64 bit system, and their 32 bit versions when installing on a 32 bit system.

You will obviously also want to use a Check as in Martin's example to make sure you are only installing the correct binaries.

Ex:

#define MyAppName "MyAwesomeApp"
[Setup]
ArchitecturesInstallIn64BitMode=x64
AppName={#MyAppName}
DefaultDirname={pf}\{#MyAppName}

[Files]
Source: "MyApp_32bit.exe"; DestDir: "{app}"; Check not Is64BitinstallMode;
Source: "MyApp_64bit.exe"; DestDir: "{app}"; Check Is64BitinstallMode;

Upvotes: 8

Related Questions