How to detect windows 32bit or 64 bit using NSIS script?
Asked Answered
O

3

35

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?

Opportunity answered 5/11, 2012 at 9:28 Comment(1)
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-binariMuffler
N
39

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
Neoclassic answered 5/11, 2012 at 9:59 Comment(2)
Thanks.In that url said ; File some.dll # extracts to C:\Windows\System32. what is some.dll? which file it mean to?. i could not able to understandOpportunity
oh thanks.that {If} part where am i put in my script? .oninit()? or some other place?Opportunity
C
65

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}       
Crater answered 3/3, 2014 at 13:23 Comment(3)
Does this detect all 64-bit architectures or just windows xp x64?Calorifacient
I couldn't find a definite answer, I always assumed it does! I've tested it on Windows 7 64bit and Windows XP 64 bit and it worked. I never had any trouble with it on any Windows platformCrater
It applies to all 64-bit versions of Windows. (It calls IsWow64Process internally)Neoclassic
N
39

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
Neoclassic answered 5/11, 2012 at 9:59 Comment(2)
Thanks.In that url said ; File some.dll # extracts to C:\Windows\System32. what is some.dll? which file it mean to?. i could not able to understandOpportunity
oh thanks.that {If} part where am i put in my script? .oninit()? or some other place?Opportunity
S
1

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! =)

Sulphathiazole answered 5/6, 2017 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.