代码之家  ›  专栏  ›  技术社区  ›  Albert Mulder

NSIS检查是否安装了应用程序

  •  0
  • Albert Mulder  · 技术社区  · 7 年前

    在安装我的应用程序之前,我正在检查是否安装了应用程序。这是我正在使用的代码

    ; Check to see if already installed
      ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D9C50188-12D5-4D3E-8F00-682346C2AA5F}" "UninstallString"
      IfFileExists $R0 +1 NotInstalled
      MessageBox MB_OK|MB_TOPMOST "App Installed" 
    
    Goto InstallCont2
    

    如果名称是实际名称,则该选项有效,但如果名称如下所示:

    {D9C50188-12D5-4D3E-8F00-682346C2AA5F}

    然后它没有检测到它。我试着在行中输入不同的“或”,但找不到正确的代码。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Anders    7 年前

    路径中的GUID无关紧要。如果无法读取该值,则可能是64位问题,您可能需要 SetRegView . Process Monitor 可能会有所帮助,但在挖掘调试工具之前,你应该先做 MessageBox mb_ok $R0 之后 ReadRegStr 看看它是否读到了什么。

    你不能只是打电话 IfFileExists UninstallString

    您可以使用这样的方法来获取路径:

    !macro GetAppPathFromCommandLine output input
    Push '${input}'
    Call GetAppPathFromCommandLine
    Pop ${output}
    !macroend
    Function GetAppPathFromCommandLine
    Exch $0 ; input
    Push $1 ; find
    Push $2 ; start offset
    Push $3 ; temp
    Push $4 ; pos
    StrCpy $1 ' '
    StrCpy $2 ""
    StrCpy $3 $0 1
    StrCpy $4 -1
    StrCmp $3 '"' 0 +4
    StrCpy $1 $3
    StrCpy $2 1
    StrCpy $4 ""
    loop:
    IntOp $4 $4 + 1
    StrCpy $3 $0 1 $4
    StrCmp $3 "" done
    StrCmp $3 $1 done loop
    done:
    IntOp $4 $4 - $2
    StrCpy $0 $0 $4 $2
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Exch $0
    FunctionEnd
    
    Section
    !insertmacro GetAppPathFromCommandLine $0 'c:\foo\bar.exe'
    DetailPrint |$0|
    !insertmacro GetAppPathFromCommandLine $0 '"c:\foo bar\baz.exe"'
    DetailPrint |$0|
    !insertmacro GetAppPathFromCommandLine $0 'c:\foo\bar.exe param1 "pa ra m2" param3'
    DetailPrint |$0|
    !insertmacro GetAppPathFromCommandLine $0 '"c:\foo bar\baz.exe" param1 "pa ra m2" param3'
    DetailPrint |$0|
    SectionEnd