简体   繁体   中英

NSIS Check for app installed

I am trying to check to see if an app is installed before I install mine. Here is the code I am using

; 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

It works if the name is an actual name, but if the name is like this:

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

then it does not detect it. I have tried putting in different " or ' on the line, but cant find the correct code for it.

A GUID in the path does not matter. If you cannot read the value it might be a 64-bit issue and you might need SetRegView . Process Monitor might be able to help but before digging out debugging tools you should just do MessageBox mb_ok $R0 after ReadRegStr to see if it read anything.

You cannot just call IfFileExists on strings read from UninstallString because the string might contain quotes and/or command line arguments that you need to strip away first.

You can use something like this to get just the path:

!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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM