簡體   English   中英

NSIS 腳本未安裝在正確的目錄中

[英]NSIS script not installing in correct directory

我正在嘗試制作安裝腳本:

  • 在 32 位電腦上:tapi_32bits.tsp in C:\\windows\\system32
  • 在 64 位電腦上: 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 位電腦上,它會將兩個文件(tapi_64bits.tsp 和 tapi_32bits.tsp)放在 Syswow64 文件夾中。 安裝程序確實說它安裝在正確的文件夾中,但兩個文件都在 Syswow64 文件夾中。 我究竟做錯了什么?

NSIS 是一個 32 位應用程序,因此它受文件重定向的影響。

您必須使用x64.nsh ,它具有檢測 WOW64 和禁用重定向的代碼(盡快將其重新打開)。 另一種選擇是提取到$windir\\sysnative但這更像是一種黑客攻擊,並且在 XP 64 上不起作用。

以下代碼應該可以工作。

!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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM