Old 19th May 2007, 04:15   #1
BobL
Junior Member
 
Join Date: May 2007
Location: Superior, Colorado
Posts: 2
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
BobL is offline   Reply With Quote
Old 19th May 2007, 04:55   #2
BobL
Junior Member
 
Join Date: May 2007
Location: Superior, Colorado
Posts: 2
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
BobL is offline   Reply With Quote
Old 19th May 2007, 10:31   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
It might be better to use it in .onInit in case you decide to use a directory page.

Stu
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump