简体   繁体   English

NSIS检查安装的应用程序

[英]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} {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. 路径中的GUID无关紧要。 If you cannot read the value it might be a 64-bit issue and you might need SetRegView . 如果无法读取该值,则可能是一个64位问题,并且可能需要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. 进程监视器也许能帮助,但挖掘出的调试工具之前,你应该只是做MessageBox mb_ok $R0ReadRegStr ,看它是否读什么。

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. 您不能仅对从UninstallString读取的字符串调用IfFileExists ,因为该字符串可能包含引号和/或命令行参数,您需要先将它们删除。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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