NSIS脚本未安装在正确的目录中

时间:2012-05-25 13:32:19

标签: nsis system32 syswow64

我正在尝试制作安装脚本:

  • on 32bits pc:C:\windows\system32
  • 中的tapi_32bits.tsp
  • on 64bits pc:C:\Windows\System32中的tapi_64bits.tsp和C:\Windows\SysWOW64中的tapi_32bits.tsp

这是我写的剧本:

; The name of the installer
Name "TAPI Installer"

; The file to write
OutFile "TAPI Installer"

; The default installation directory
InstallDir $DESKTOP

;--------------------------------

; Install to the correct directory on 32 bit or 64 bit machines
Section
IfFileExists $WINDIR\SYSWOW64\*.* Is64bit Is32bit
Is32bit:
    ; Set output path to the installation directory.
    SetOutPath $SYSDIR

    ; Put file there
    File tapi_32bits.tsp

;   SectionEnd MessageBox MB_OK "32 bit"
        SetRegView 32
        StrCpy $INSTDIR "$PROGRAMFILES32\LANDesk\Health Check"
    GOTO End32Bitvs64BitCheck

Is64bit:
    ; install in  C:\Windows\System32
    SetOutPath $WINDIR\System32\

    ; file to put there
    File tapi_64bits.tsp

    ; install in C:\Windows\SysWOW64
    SetOutPath $WINDIR\SysWOW64

    ; file to put there
    File tapi_32bits.tsp


    ;SectionEnd MessageBox MB_OK "32 bit"
        SetRegView 32
        StrCpy $INSTDIR "$PROGRAMFILES32\LANDesk\Health Check"
        GOTO End32Bitvs64BitCheck    
    MessageBox MB_OK "64 bit"
        SetRegView 64
        StrCpy $INSTDIR "$PROGRAMFILES64\LANDesk\Health Check"

End32Bitvs64BitCheck:
SectionEnd
;--------------------------------

但是在64位pc上它将两个文件(tapi_64bits.tsp和tapi_32bits.tsp)放在Syswow64文件夹中。安装程序确实说它安装在正确的文件夹中,但两个文件都在Syswow64文件夹中。我究竟做错了什么?

2 个答案:

答案 0 :(得分:5)

NSIS是一个32位应用程序,因此它受file redirection的影响。

您必须使用x64.nsh,它具有检测WOW64的代码并禁用重定向(尽快重新打开)。另一个选择是提取到$windir\sysnative,但这更像是一个黑客攻击,并且在XP 64上不起作用。

答案 1 :(得分:-1)

以下代码应该有效。

!include x64.nsh    
; Install to the correct directory on 32 bit or 64 bit machines
Section
${If} ${RunningX64}
; install in  C:\Windows\System32
SetOutPath $WINDIR\System32\

; file to put there
File tapi_64bits.tsp

; install in C:\Windows\SysWOW64
SetOutPath $WINDIR\SysWOW64

; file to put there
File tapi_32bits.tsp
${Else}
; Set output path to the installation directory.
SetOutPath $SYSDIR
; Put file there
File tapi_32bits.tsp
${EndIf}

SectionEnd