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

倾然丶 夕夏残阳落幕 提交于 2019-12-20 11:52:30

问题


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?


回答1:


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



回答2:


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}       



回答3:


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



来源:https://stackoverflow.com/questions/13229212/how-to-detect-windows-32bit-or-64-bit-using-nsis-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!