Przunk
Przunk

Reputation: 83

NSIS installer - define installer and system x32/x64

I am trying to set proper installation folder for my application. Can I detect if installer is for 32 or 64 bit system? Because now when I install x32 application on x64 system, the InstallDir is incorrect.

I have one build script for x32 and x64 installer and I use x64.nsh to define program files path. But here is problem: Even if installer detects x64 system, if current build is x32, it will be still installed in "C:\Program Files" instead of "C:\Program Files (x86)".

On worst case scenario I will have to create two build scripts for two installers (x32, x64), but I want to avoid it.

So, is there any way to define if installer is for 32 or 64 bit systems?

Upvotes: 4

Views: 9801

Answers (2)

anr78
anr78

Reputation: 1318

I had the same issue. Ended up using a wrapper script that passed the arch of the application to the nsi script (makensis.exe /DARCH=x86/x64) and something like this in the nsi script itself:

${If} ${RunningX64}
  ${If} ${ARCH} == "x64"
    StrCpy $InstDir "$PROGRAMFILES64\${PROGNAME}"
  ${Else}
    StrCpy $InstDir "$PROGRAMFILES32\${PROGNAME}"
  ${Endif}
${Else}
  ${If} ${ARCH} == "x64"
    Quit
  ${Else}
    StrCpy $InstDir "$PROGRAMFILES\${PROGNAME}"
  ${Endif}
${EndIf}

Upvotes: 3

Anders
Anders

Reputation: 101656

If the application you are installing is always 32bit then just use InstallDir "$ProgramFiles\MyApp"

If the installer contains both a 32bit and 64bit version of the same app and you want to install the "native" version you have to set $InstDir yourself in .onInit:

!include LogicLib.nsh
!include x64.nsh
; Don't use InstallDir[RegKey] so $InstDir is empty by default

Function .onInit
${If} $InstDir == "" ; Don't override setup.exe /D=c:\custom\dir
    ${If} ${RunningX64}
        StrCpy $InstDir "$ProgramFiles64\MyCompany\MyApp"
    ${Else}
        StrCpy $InstDir "$ProgramFiles32\MyCompany\MyApp"
    ${EndIf}
${EndIf}
FunctionEnd

Section
SetOutPath $InstDir
${If} ${RunningX64}
    File "AMD64\myapp.exe"
${Else}
    File "i386\myapp.exe"
${EndIf}
SectionEnd

Upvotes: 0

Related Questions