Skip to content
⌘ NSIS Forum Archive

Problem using ${RunningX64}

10 posts

jai123#

Problem using ${RunningX64}

I am using the code below in several parts of my script.

${If} ${RunningX64}
; 64bit bits go here
${Else}
; 32bit bits go here
${EndIf}

In one function it runs perfectly fine, but the other calls will not work unless they are used after the initial call that executed correctly.

I have not been able to find any logical reason for this behavior. I have included both the LogicLib.nsh and x64.nsh heather files, but it goes through the 64 bit section.

What could it be? There does not seem to be any macros to initialize prior their use. Any ideas?
jai123#
In the main.nsi script you can see the explanation of the problems.

If Call installDrivers is executed before Call installCNCInterface, RunningX64 will work fine for both. If Call installDrivers is executed after Call installCNCInterface, the macro will not work for installCNCInterface, but it will work for installDrivers.

Call un.uninstallDrivers will never work

The only way I have tried this out is in a 32 bit system, in which chooses the 64 bit option.

# main.nsi file

!include "LogicLib.nsh"             ; Library for logical statements 
!include "x64.nsh"                  ; Macros for x64 machines

....
....
....

# Techno CNC Interface 
SectionGroup /e "!CNC Software" SecCNC_Software
    Section "Interface" SecCNC_Interface

        SetRebootFlag true
        ;Call installDrivers      WHEN THIS LINE IS ADDED, installCNCInterface uses properly RunningX64 macro 

        # creates a temp directory in which we will work.
        setOutPath $INSTDIR
        Call installVB6Runtimes
        Call installCNCInterface   IT WILL RUN PROPERLY THE MACRO DEPENDING ON calling installDrivers before calling this function

	    WriteUninstaller "$InstDir\uninstaller.exe"

    SectionEnd
SectionGroupEnd

....
....
....

# Uninstalle Components

Section "uninstall"
 
   Call un.uninstallDrivers  NEVER CALL PROPERLY THE runningX64 macro

    # Delete uninstaller
    delete "$InstDir\uninstall.exe"
 
SectionEnd


######################################################
# Secondary.nsh file

!macro  extractDriverFiles

    # extracts respective drivers content
    ${If} ${RunningX64}
        file Drivers\x64\*.*
    ${Else}
        file Drivers\x86\*.*
    ${EndIf}

!macroend

....
....
....

Function disableDevices

    # Assures that the kernel plug in and pci device are not open or service
    execWait "wdreg_gui -name pciservo -silent uninstall"   ;-silent flag will omit error messages when the drivers have never been installed before.
    ${If} ${RunningX64}
        execWait 'wdreg_gui -inf "$OUTDIR\TechnoPCIController_device.inf" -silent disable'
    ${Else}
        execWait 'wdreg_gui -inf "$OUTDIR\pciservo.inf" -silent disable'
    ${EndIf}

FunctionEnd


Function setupDrivers

    !insertmacro extractDriverFiles
    Call disableDevices     ; to install the drivers cleanly, no devices have to be enabled
    !insertmacro cleanFileSystem 

FunctionEnd

Function executeDriverInstallation
    ${If} ${RunningX64}
       .....
    ${Else}
        .....
    ${EndIf}
FunctionEnd

Function installDrivers

    # save the original output dir
    Push $R0
    StrCpy $R0 $OUTDIR 
    setOutPath $TEMP\Drivers

    Call setupDrivers
    Call executeDriverInstallation
    
    # Remove temporal files
    setOutPath $TEMP     ; output directory has to be different than deleted below. Otherwise, NSIS will not delete them.
    RMDir /r "$TEMP\Drivers"
FunctionEnd

# ---------------------------------------------
# Uninstallation 

Function un.executeDriverUninstallation

    # Assures that there are no services running or connected devices.
    ${If} ${RunningX64}
        ..............
    ${Else}
        .............
    ${EndIf}
FunctionEnd

Function un.uninstallDrivers

    # save the original output dir
    Push $R0
    StrCpy $R0 $OUTDIR 
    setOutPath $TEMP\Drivers

    !insertmacro extractDriverFiles
    Call un.executeDriverUninstallation
    !insertmacro cleanFileSystem

    # Remove temporal files
    setOutPath $TEMP     ; output directory has to be different than deleted below. Otherwise, NSIS will not delete them.
    RMDir /r "$TEMP\Drivers"

    # recover output dir
    setOutPath $R0
    Pop $R0

FunctionEnd

####################################
# AnotherSupport.nsh

!include "LogicLib.nsh"             ; Library for logical statements 
!include "x64.nsh"                  ; Macros for x64 machines

Var ALREADY_INSTALLED
Var Version

Function installCNCInterface
 
    ............
   
    # user mode pnp file
    ${If} ${RunningX64}
        ..........
    ${Else}
        ..........
    ${EndIf}

    .......
FunctionEnd
Anders#
I can't really get your example to fail on a 32 bit XP system.

Just for fun, insert this before the ${If} that fails:

System::Call kernel32::GetCurrentProcess()i.s
System::Call 'kernel32::IsWow64Process(is,*i.r1)i.r0 ?e'
pop $2
MessageBox mb_ok "IsWow64=$1,ret=$0,gle=$2" 
jai123#
Anders:

The code that you suggested always returns

IsWow64=0,ret=1,gle=80
I am not sure what ret=1 and gle=80 means, but it seems that it is confirming that is 32 to bit all the time. Might be something wrong with the RunningX64 macro? maybe I am using an outdated one?

Here is the code

!macro _RunningX64 _a _b _t _f
!insertmacro _LOGICLIB_TEMP
System::Call kernel32::GetCurrentProcess()i.s
System::Call kernel32::IsWow64Process(is,*i.s)
Pop $_LOGICLIB_TEMP
!insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
!macroend

!define RunningX64 `"" RunningX64 ""`
Thanks
Anders#
ret=1 means the function worked correctly (Ignore GLE on success).

The macro is probably not the problem. Is it possible that you have a goto or hardcoded jump (+3 etc) in your code?
jai123#
The problem was a macro that I was using for File redirection. The code is below.

I do not understand why the redefinition of RunningX64 was sometimes causing the symptoms that I mentioned above, but I just got rid of it.

Thanks

!include x64.nsh

Var SYSWOW64DIR
!macro _SystemDirsInit
${DisableX64FSRedirection}
${If} ${RunningX64}
StrCpy $SYSWOW64DIR $WINDIR\SysWOW64
${Else}
StrCpy $SYSWOW64DIR $SYSDIR
${EndIf}

!ifdef RunningX64
!undef RunningX64
!endif
!define RunningX64 `$SYSWOW64DIR != $SYSDIR`

!macroend
!define SystemDirsInit `!insertmacro _SystemDirsInit`

!endif
Anders#
You should only disable FSRedirection for a short time to install files, then enable it again since it will prevent proper dll loading etc...