NSIS检查安装的应用程序

时间:2017-10-13 04:09:18

标签: nsis

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

; 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 个答案:

答案 0 :(得分:0)

路径中的GUID无关紧要。如果您无法读取该值,则可能是64位问题,您可能需要SetRegViewProcess 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