2012-11-05 100 views
26

我已經爲java項目編寫了nsis腳本。我在我的項目中有批處理文件。我已經爲Windows 32位和64位編寫了批處理文件。安裝後,我已經開始使用Exec命令自動啓動批處理文件。 32位windows.but同時這是不行的64位bit.so我的懷疑,所以我懷疑安裝之前,我應該檢查是否Windows是32位或64位版本。請分享您的意見如何檢查?如何使用NSIS腳本檢測Windows 32位或64位?

+0

沒有措辭作爲一個重複的問題,但它是相同的:[use-one-nsis-installer-to-install-32-bit-binaries-on-32-bit-os-and-64-bit- binari](http://stackoverflow.com/questions/11126629/use-one-nsis-installer-to-install-32-bit-binaries-on-32-bit-os-and-64-bit-binari) – nawfal

回答

25

使用RunningX64宏在x64.nsh頭:

!include LogicLib.nsh 
!include x64.nsh 

Section 
${If} ${RunningX64} 
    DetailPrint "64-bit Windows" 
${Else} 
    DetailPrint "32-bit Windows" 
${EndIf} 
SectionEnd 
+0

謝謝。在那個URL說:將some.dll#提取文件提取到C:\ Windows \ System32。什麼是some.dll?它意味着什麼文件?我無法理解 – Ami

+0

這只是一些示例代碼,{If}行是重要的部分... – Anders

+1

oh thanks.that {If}部分我放在腳本中的位置? .oninit()?或其他地方? – Ami

58

對於未來的懶惰的Google - 一個小片段:

包含此:

!include x64.nsh 

,並使用此,如果:

${If} ${RunningX64} 
    # 64 bit code 
${Else} 
    # 32 bit code 
${EndIf}  
+0

這是否檢測到所有64位體系結構或只是Windows XP x64? –

+0

我找不到明確的答案,我總是認爲它確實!我已經在Windows 7 64位和Windows XP 64位上測試過它,它工作。我從來沒有在任何Windows平臺上遇到任何問題 – Nitay

+0

它適用於所有64位版本的Windows。 (它在內部調用IsWow64Process) – Anders

-1

這是我用大部分的時間,而不需要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 

現在$位持有其中任何一個可以這樣使用64或32:

${If} $Bit == 64 
    ...64-bit code.. 
${Else} 
    ..32-bit code... 
${EndIf} 

或者

StrCmpS $Bit 64 SixtyFour ThirtyTwo 

SixtyFour: 
    ... 
    Goto End 
ThirtyTwo: 
    ... 
End: 

我用StrCmpS,因爲我相信這是一個更快的頭髮。大聲笑。希望這可以幫助! =)

相關問題