为了比较版本,我必须找出我的应用程序是否已经安装。 我使用注册表存储整个必要的信息,如果我能以某种方式从注册表中读取字符串将是非常有用的。这里的主要问题是我不知道我自己的GUID,它是在之前的安装过程中随机化的。
为了生成我的注册表路径,我编写了以下脚本:
Function .onInit
${If} ${RunningX64}
StrCpy $R0 "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
${Else}
StrCpy $R0 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
${EndIf}
FunctionEnd
主段:
Section "Main" sec
System::Call 'ole32::CoCreateGuid(g .s)'
Pop $0
WriteRegStr HKLM "$R0\$0" 'DisplayVersion' '${AppVersion}'
SectionEnd
所以,基本上我需要找到一种方法来读取DisplayVersion
字符串。我希望FindFirst
有一些变化但是对于注册表。
答案 0 :(得分:0)
使用EnumRegKey
枚举注册表项:
!include LogicLib.nsh
Section
StrCpy $0 0
loop:
EnumRegKey $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" $0
StrCmp $1 "" done
ReadRegStr $2 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "DisplayName"
${If} $2 == "My Application Name"
ReadRegStr $2 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "DisplayVersion"
DetailPrint "TODO: Compare $2 to version here..."
${EndIf}
IntOp $0 $0 + 1
Goto loop
done:
SectionEnd