Skip to content
⌘ NSIS Forum Archive

$PROGRAMFILES on x64

12 posts

sunghun#

$PROGRAMFILES on x64

I want to install my "64-BIT" executable binaries on "C:\Program Files\MyApp".

But NSIS $PROGRAMFILES variable always indicates
"C:\Program Files (x86)".

How can I correct this problem?
Thanks in advance.
sunghun#
Surely included that file,
and I also tried $(DisableX64FSRedirection) in .onInit,
but same problem...
Red Wine#
; RunningX64 checks if the installer is running on x64.
;
; ${If} ${RunningX64}
; MessageBox MB_OK "running on x64"
; ${EndIf}
;
; DisableX64FSRedirection disables file system redirection.
; EnableX64FSRedirection enables file system redirection.
;
; ${DisableX64FSRedirection}
; DetailPrint $SYSDIR # prints C:\Windows\System32
; ${EnableX64FSRedirection}
; DetailPrint $SYSDIR # prints C:\Windows\SysWOW64
Red Wine#
Something like this should be the way to go:
!include x64.nsh

Function .onInit
${If} ${RunningX64}
${EnableX64FSRedirection}
${else}
MessageBox MB_OK "Sorry this application runs only on x64 machines"
Abort
${EndIf}
StrCpy '$INSTDIR' '$PROGRAMFILES\My Application'
FunctionEnd
kichik#
You should actually disable redirection only right before using something that relies on it and enable it back right away. If you don't, some weird stuff can happen.
sunghun#
Thank you but still not solved.

I tested the following 3 msgboxes in .onInit,

MsgBox MB_OK "$PROGRAMFILES 1"
${DisableX64FSRedirection}
MsgBox MB_OK "$PROGRAMFILES 2"
${EnableX64FSRedirection}
MsgBox MB_OK "$PROGRAMFILES 3"

All output contained "(x86)"...

But maybe I'm wrong because
$SYSDIR (instead of $PROGRAMFILES) was also
not changed at these 3 msgbox test.
Red Wine#
Just in case...
!include x64.nsh

Function .onInit
${If} ${RunningX64}
${EnableX64FSRedirection}
${else}
MessageBox MB_OK "Sorry this application runs only on x64 machines"
Abort
${EndIf}
FunctionEnd

Section -
Detailprint '$SYSDIR'
DetailPrint '$WINDIR'
DetailPrint '$PROGRAMFILES'
SectionEnd
sunghun#
Thanks,


!include "MUI.nsh"
!include "x64.nsh"

Name "Modern UI Test"
OutFile "Basic.exe"

InstallDir "$PROGRAMFILES\Modern UI Test"
InstallDirRegKey HKCU "Software\Modern UI Test" ""

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "Dummy Section" SecDummy
SetOutPath "$INSTDIR"
WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd

Section "Uninstall"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd

Function .onInit
${If} ${RunningX64}
${EnableX64FSRedirection}
${Else}
MessageBox MB_OK "x64 test only"
Abort
${EndIf}
FunctionEnd

Section -
DetailPrint '$SYSDIR'
DetailPrint '$WINDIR'
DetailPrint '$PROGRAMFILES'

MessageBox MB_OK "$PROGRAMFILES 1"
${DisableX64FSRedirection}
MessageBox MB_OK "$PROGRAMFILES 2"
${EnableX64FSRedirection}
MessageBox MB_OK "$PROGRAMFILES 3"
SectionEnd
The details output:

Output folder: C:\Program Files (x86)\Modern UI Test
Created uninstaller: C:\Program Files (x86)\Modern UI Test\Uninstall.exe
C:\WINDOWS\system32
C:\WINDOWS
C:\Program Files (x86)
Completed
MessageBox output was "C:\Program Files (x86) ?".
Red Wine#
Everything appears as expected in your script, though, the redirection seems that fails. I don't know what else to think. Since I have not x64 system I can't help further.
kichik#
The problem with $PROGRAMFILES is that it's read from the registry. The same goes to $COMMONFILES. What should happen, is that SHGetSpecialFolderLocation should be called first and then, only if it failed, the registry should be read. Please submit a bug report about this.