Archive: Using InstallDirRegKey twice


Using InstallDirRegKey twice
Hi all,

I have searched the board but can't find an answer, so here goes....

I need to read a reg key to set the $INSTDIR variable, then compare it with the default $INSTDIR variable which I am setting earlier. If they are the same, then I know that the reg key does not exist (or the value could be the same), so I have to read another reg key for the install path. I am doing this because previous versions of the software put the InstallDir key in the HKCU but current versions put it in HKLM. So, I have to check HKCU first. If a value is read from that key, then I don't need to check the HKLM.

Here's my script:

; set the default
InstallDir "$PROGRAMFILES\${MUI_APPNAME}"

; read from my HKCU reg key
InstallDirRegKey HKCU "SOFTWARE\${MUI_APPNAME}" "InstallDir"

; compare the reg key to my default
; if they are the same, the reg key doesn't exist...
StrCmp $INSTDIR "$PROGRAMFILES\${MUI_APPNAME}" 0

; ... so read the reg key from the HKLM root
InstallDirRegKey HKLM "SOFTWARE\${MUI_APPNAME}" "InstallDir"

But, I get compilation errors because StrCmp must be in a Section or Function. But if I put all of that in a section or function, I get compilation errors because the InstallDir... commands can't be in sections or functions!

The following doesn't work either:

InstallDir "$PROGRAMFILES\${MUI_APPNAME}"
InstallDirRegKey HKCU "SOFTWARE\${MUI_APPNAME}" "InstallDir"
InstallDirRegKey HKLM "SOFTWARE\${MUI_APPNAME}" "InstallDir"

If the HKLM key doesn't exist, it always uses the default $INSTDIR, so it's as if the HKCU key value doesn't matter.

Is there a way to do this?

Thanks,

Bob


Hi,

I think I figured it out. Instead of using InstallDirRegKey, I used ReadRegStr because I can use it in a section.

So here is my code:

Section GetInstDir

; read the HKCU reg value
ReadRegStr $0 HKCU "SOFTWARE\${MUI_APPNAME}" "InstallDir"

; if the value is empty...
StrCmp $0 "" 0 dirfound

; ... read the HKLM reg value
ReadRegStr $0 HKLM "SOFTWARE\${MUI_APPNAME}" "InstallDir"

; if that value is empty...
StrCmp $0 "" 0 dirfound

; ... use the default value
StrCpy $0 "$PROGRAMFILES\${MUI_APPNAME}"

dirfound:
; copy the value into $INSTDIR
StrCpy $INSTDIR $0

SectionEnd

This seems to give me the results I want, but if anyone has a better way, or if you see a problem with this, please let me know.

Thanks,

Bob


It might be better to use it in .onInit in case you decide to use a directory page.

Stu