我能否以某种方式检测32或64位操作系统而无需插件?

时间:2014-09-12 07:43:21

标签: nsis

现在我使用x64.nsh,但我可以在没有这个插件的情况下检测到它吗?

$ {If} $ {RunningX64}

MessageBox MB_OK "running on 64 bit"
File /r ${64BIT_OPENVPN_INSTALL}   
Execwait ${64BIT_OPENVPN_INSTALL}  

$ {否则}

MessageBox MB_OK "running on 32 bit"
File /r ${32BIT_OPENVPN_INSTALL}
Execwait ${32BIT_OPENVPN_INSTALL}

$ {ENDIF}

2 个答案:

答案 0 :(得分:2)

x64.nsh并不意味着特定的外部插件使用(除了系统插件):它只是一个包含文件,根据内核调用定义3个宏(即kernel32::GetCurrentProcess()kernel32::IsWow64Process())通过系统插件,可以方便地与LogicLib.nsh

一起使用

答案 1 :(得分:1)

通过查看文件和注册表项,可能有很多方法可以检测本机位数,但总有一些32位系统在%WinDir%等中以某种方式结束了SysWOW64文件夹的风险。

SetRegView测试应该是非常安全的,但是有一个小窗口,其他一些应用程序可能会在错误的时间更改注册表,从而导致错误的结果。

检测这种情况的正确方法当然是调用IsWow64Process函数,而x64.nsh标题已经为你做了。

!include LogicLib.nsh
Section
!if "${NSIS_PTR_SIZE}" > 4
DetailPrint "64-bit NSIS, this must be a 64-bit system"
!endif

${If} ${FileExists} "$WinDir\SysWOW64\kernel32.dll"
    DetailPrint "Probably not a native 32-bit system"
${EndIf}
${If} ${FileExists} "$WinDir\SysNative\kernel32.dll"
    DetailPrint "Probably a 32-bit app on a native 64-bit system (Vista+ only)"
${EndIf}

SetRegView 64
ReadRegStr $6 HKLM "Software\Microsoft\Windows\CurrentVersion" "ProgramFilesDir"
SetRegView lastused
SetRegView 32
ReadRegStr $3 HKLM "Software\Microsoft\Windows\CurrentVersion" "ProgramFilesDir"
SetRegView lastused
${If} $3 != $6
    DetailPrint "Probably a 32-bit app on a native 64-bit system"
${EndIf}

; ReadEnvStr on ProgramW6432 or PROCESSOR_ARCHITEW6432 etc
SectionEnd
相关问题