- NSIS Discussion
- Newbie Help with RegKey
Archive: Newbie Help with RegKey
LucasXX
5th September 2003 12:34 UTC
Newbie Help with RegKey
Hi I'm haveing a problem, I'm trying to detect a registry key to see if it exist, but what ever combination I try I can't get it to work
ReadRegStr $0 HKLM "Software\game\software" "Install Path"
???????????? continue
MessageBox MB_ICONINFORMATION|MB_OK "Registry path can not be found"
Abort
continue:
All I would like it to do is if the registry key exist to continue, if it doesn't then I would like it to abort, but I just don't know what the lines should be, I have try looking through the archive and docs and the forum, but what ever combination I do it won't work
I know it has to be in the Function .oninit, but I ca'nt cet it to work.
I have try the Archive IfKeyExists Macro, but all I get is
IfKeyExists not inuse or something like that
I would be gratefull for your help
Thank you
kichik
5th September 2003 12:40 UTC
IfKeyExists from the archive is the way to go if you want to check if the key exists. But as it seems, all you need is to know if the value inside it is valid. For that, simply compare it to "" using StrCmp. You can also use InstallDirRegKey.
LucasXX
5th September 2003 14:55 UTC
This seems to work, could someone confirm that it's correct and I'm right please
Thank you
Function .onInit
ReadRegStr $0 HKLM "SOFTWARE\game\software" "Install Path"
StrCmp $0 "" 0 continue
MessageBox MB_ICONINFORMATION|MB_OK "Registry path can not be found"
Abort
continue:
FunctionEnd
kichik
5th September 2003 15:02 UTC
Yes, that's a good way. But if you want to use $0 later to fill $INSTDIR you should use InstallDirRegKey and check if $INSTDIR is empty in .onInit. It will also make sure the installation path is valid and not just not empty.
LucasXX
5th September 2003 15:09 UTC
Ok I have this
Oh I should add that this is a upgrade for some files and not a exe application
InstallDir "$INSTDIR"
InstallDirRegKey HKLM "Software\game\software" "Install Path"
but how would I put $INSTDIR into the .oninit ?
you see I don't want it to be installed to anyother DIR if the Reg key doesn't exist.
I have read the InstallDirRegKey as you stated but I don't quite understand it
kichik
5th September 2003 15:13 UTC
I'm sorry, I've mixed up. InstallDirRegKey checks if it's empty for you:
If this attribute is present, it will override the InstallDir attribute if the registry key is valid, otherwise it will fall back to the InstallDir default.
LucasXX
5th September 2003 15:14 UTC
so is my little bit of script fine then?
kichik
5th September 2003 15:17 UTC
No. InstallDir sets $INSTDIR, you can't tell it to set it to its self. You must provide a default or provide nothing. If you want to abort the installation if that regkey doesn't exist just use this:
InstallDirRegKey HKLM "Software\game\software" "Install Path"
Function .onInit
StrCmp $INSTDIR "" 0 ok
MessageBox MB_OK "error..."
Abort
ok:
FunctionEnd
LucasXX
5th September 2003 15:22 UTC
so what if I put
Var GAMEDIR
Section "-InstallDir"
ReadRegStr $GAMEDIR HKLM "Software\game\software"
StrCpy $INSTDIR "$GAMEDIR"
SectionEnd
InstallDir "$INSTDIR"
InstallDirRegKey HKLM "Software\game\software" "Install Path"
and then
Function .onInit
StrCmp $INSTDIR "" 0 ok
MessageBox MB_OK "error..."
Abort
ok:
FunctionEnd
will this work
kichik
5th September 2003 15:29 UTC
Why would you want to do that? Just use the script I gave you.
This line means nothing:
InstallDir "$INSTDIR"
This line is missing a parameter:
ReadRegStr $GAMEDIR HKLM "Software\game\software"
If you don't use InstallDir, InstallDirRegKey will put the value from the registry and if it's not there or the value is invalid, it'll put nothing in it. That's what you should use, my script.
LucasXX
5th September 2003 15:31 UTC
ok then thanks, won't bother you again :)
LucasXX
5th September 2003 15:58 UTC
Sorry about this I know I said I wouldn't bother you again,
so what would happen if I removed the line InstallDir
is InstallDirRegKey used instead?
Or do I have to have InstallDir line in the script
I only ask because if I have InstallDir "$PROGRAMFILES\game" it overrides the InstallDirRegKey and the Function .oninit script you supplied doesn't check if the install path is valid, if I delete the Regkey from the registry is will still install, which I don't want it to do.
or could I put InstallDir ""
if not what do I put so it will not override InstallDirRegKey?
Sorry but it can be confusing and my apologise as you have been very patient so far.
LucasXX
5th September 2003 19:24 UTC
Hi just wondered if anyone could answer my question
kichik
5th September 2003 20:03 UTC
As the quote said InstallDirRegKey overrides InstallDir if the key exists and contains a valid path. If you have InstallDir in your script it will fall back to whatever you've defined using InstallDir instead to "" as you wish.
You should simply not use InstallDir.
LucasXX
5th September 2003 20:54 UTC
Thank you