Change the default installation folder in NSIS

I am writing an installer for Windows using nsis. This installer contains a web application that runs on top of xampp, so xampp is also installed as a service with this application. But xamp gives a problem when it is installed on a 64-bit machine in Windows 7. This is due to a directory path problem in C: \ Program Files (x86), as mentioned here.

XAMPP Solution? I have it installed on my Windows XP Dual Boot Machine

But at present, the unattended installation path is set by the installer as follows.

C:\Program Files (x86)\myapplication

The installer script has only the following macro to add a directory selection selection page.

!insertmacro MUI_PAGE_DIRECTORY

As a solution, I am going to follow these steps.

  • Change the default directory to c: \ Program Files
  • If the user selects the x86 folder, an error message is displayed to select a different directory.

To do this, I need to get the path to the installation directory using

$INSTDIR

and

  • check if there is an x86 substring with this path
  • if it gives error messages.
  • Change the default path to c: \ Program Files

Since I am not very familiar with nsis, I cannot write this program.

Can someone help me on this issue?

+3
source share
2 answers

In win7 / 64, 64-bit program files can be obtained from a 32-bit application through an environment variable %ProgramW6432%.

You can try to get it with ReadEnvStr:

  • on a 32-bit system it will return an empty string
  • on a 64-bit system, it will return c:\program files(if not configured elsewhere)

, :

ReadEnvStr $0 ProgramW6432
StrCmp $0 "" 0 +3
MessageBox MB_OK "it is a 32b system"
goto +2
MessageBox MB_OK "it is a 64b system"

:

ReadEnvStr $0 ProgramW6432
StrCmp $0 "" +2 0
StrCpy $INSTDIR $0

. Program Files (x86), .onVerifyInstDir, Anders for , , , :

Function .onVerifyInstDir
  ReadEnvStr $0 "ProgramFiles(x86)"
  StrCmp $0 $INSTDIR 0 PathGood
  MessageBox MB_OK "directory not valid for installation"
  Abort
PathGood:
FunctionEnd

(x86) .

+3

NSIS $PROGRAMFILES32 $PROGRAMFILES64:

InstallDir "$PROGRAMFILES64\myapp"
+7

All Articles