简体   繁体   English

如何使用NSIS脚本检测32位或64位的窗口?

[英]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: 对于未来懒惰的googlers - 一个小片段:

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: x64.nsh标头中使用RunningX64宏:

!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 这是我大部分时间都使用的,而不需要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: 现在$ Bit持有64或32,可以像这样使用:

${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. 我使用StrCmpS因为我相信这是一个更快的头发。 Lol. 大声笑。 Hope this helps! 希望这可以帮助! =) =)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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