NSIS检查安装的应用程序
问题描述:
我试图在安装我的程序之前检查是否安装了应用程序。下面是我使用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}
然后它不检测它。我试过在不同的“或”上放行,但是找不到正确的代码
答
路径中的一个GUID并不重要如果你不能读取它的值可能是一个64位的问题,您可能需要SetRegView
。Process Monitor也许能帮助,但挖掘出的调试工具之前,你应该只是做MessageBox mb_ok $R0
ReadRegStr
后,看它是否读什么。
你不能只是调用IfFileExists
从UninstallString
阅读,因为该字符串可能包含字符串引号和/或命令行参数,您需要首先删除。
Yo你可以使用类似这样的东西来获取路径:
!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