35
votes

I have written nsis script for java project.I have Batch file in my project.I have written batch file for commonly windows 32bit and 64 bit.After installing i have started batch file automatically using Exec command.Its woks fine in 32bit windows.but the same time this is not worked well in 64 bit.so i suspect that before installing i should check whether windows is 32 bit or 64 bit version.please share your views how to check?

3
Not worded as a duplicate question, but its the same: use-one-nsis-installer-to-install-32-bit-binaries-on-32-bit-os-and-64-bit-binarinawfal

3 Answers

64
votes

For future lazy googlers - A small snippet:

Include this:

!include x64.nsh

And use this if:

${If} ${RunningX64}
    # 64 bit code
${Else}
    # 32 bit code
${EndIf}       
37
votes

Use the RunningX64 macro in the x64.nsh header:

!include LogicLib.nsh
!include x64.nsh

Section
${If} ${RunningX64}
    DetailPrint "64-bit Windows"
${Else}
    DetailPrint "32-bit Windows"
${EndIf}  
SectionEnd
1
votes

Here's what I use most of the time without the need for x64.nsh

Var Bit
System::Call "kernel32::GetCurrentProcess()i.s"
System::Call "kernel32::IsWow64Process(is,*i.r0)"
StrCmpS $0 0 +3
StrCpy $Bit 64
Goto +2
StrCpy $Bit 32

Now $Bit holds either 64 or 32 which can be used like this:

${If} $Bit == 64
     ...64-bit code..
${Else}
     ..32-bit code...
${EndIf}

Or

StrCmpS $Bit 64 SixtyFour ThirtyTwo

SixtyFour:
    ...
    Goto End
ThirtyTwo:
    ...
End:

I used StrCmpS as I believe it's a hair faster. Lol. Hope this helps! =)