简体   繁体   中英

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

我已经为java项目编写了nsis脚本。我的项目中有批处理文件。我已经为常用的Windows 32位和64位编写了批处理文件。安装完成后,我已经使用Exec命令自动启动了批处理文件。它在32位windows中运行得很好。但是同时这在64位中运行不佳。所以我怀疑在安装之前我应该​​检查一下Windows是32位还是64位版本。请分享您的看法如何检查?

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}       

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM