- NSIS Discussion
- Install using Registry Key
Archive: Install using Registry Key
JediKnight2
15th January 2008 03:12 UTC
Install using Registry Key
I have searched and tried every thing I can think of and have read, but I cannot seem to get this to work.
I have a registry key at HKLM "SOFTWARE\MyProgram" ""
Basically it shows the location of the install. I have a patched file that needs to go into the location the key shows, but in a sub folder so if the key shows C:\Program Files\MyProgram, I need it in C:\Program Files\MyProgram\lib
I have tried this but it just wont work
Section "MainSection" SEC01
ReadRegStr $0 HKLM SOFTWARE\MyProgram ""
IfFileExists $0\lib +2
StrCpy $0 "$INSTDIR"
SetOutPath $0
SetOverwrite on
File "file.txt"
SectionEnd
I also tried to add the lib part on the SetOutPath, no worky
Red Wine
15th January 2008 05:07 UTC
Assuming that the mentioned key behaves like the InstallDirRegKey and shows the installation dir, all you need is:
ReadRegStr $0 HKLM "SOFTWARE\MyProgram" ""
SetOutPath "$0\lib"
or in function .onInit
ReadRegStr $0 HKLM "SOFTWARE\MyProgram" ""
StrCpy $INSTDIR "$0\lib"
IFX
15th January 2008 22:01 UTC
Well, I searched for the term registry folder and read 10 pages worth of stuff and tried all of them. Using the onit, getParent, read the key, etc. For some reason it just wont pick it up. I have used the install directory registry key string and it will read fine from the key. However, when I try to use a read reg key in the section it isn't working.
I tried what you had Red, but it didn't work either...I am posting my code...
Also, for some reason my other account went dead? Not sure what happened to it.
IFX
15th January 2008 22:14 UTC
Forgot the file
kichik
15th January 2008 22:17 UTC
InstallDirRegKey has some minor processing applied to the registry key specified. For example, if it detects a path to an executable, it removes the last part. Make sure $0 contains exactly what you think it contains.
You should use $SYSDIR instead of C:\Windows\System32.
IFX
16th January 2008 00:13 UTC
When it reads the registry key it pulls
C:\Program Files\MyProgram
If I use InstallDirRegKey in a non section it correctly pulls the directory...however what I need to do is append what it pulled and add \lib...so I tried various ways in the Section to read the key and add the \lib..tried Reds way and it didn't work for some reason...it might be something in my script that is why I posted it....I'm lost, it's like it totally ignores the setoutputpath in the Section
Red Wine
16th January 2008 05:04 UTC
According to the code that you've posted above, you're attempting to read a registry key which obviously doesn't exist, so $0 should be empty and the error flag up.
The key doesn't exist because your script missing that part where it should create it upon successful installation.
IFX
16th January 2008 14:21 UTC
Something isn't right...the key is there because I can see it in the registry and it is at HKLM Software\MyProgram There are two strings in there...one is a default string and another is a DB location. If I take out the ReadRegStr part in the Section and use InstallDirRegKey HKLM "SOFTWARE\${SHORTNAME}" "" it correctly sets the install location. So that is where I am confused...I take the InstallDirRegKey out and use ReadRegStr in the Section and it doesn't work....
Afrow UK
16th January 2008 15:31 UTC
Check the value of $0 after you read it from the registry using a message box.
Stu
IFX
22nd January 2008 13:19 UTC
Ok...I see what is going on, but I haven't figured out how to fix it. I just took that page off since it is a patch anyway..it IS going to the right directory, however when it goes to this page
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
it is printing out the wrong directory not the one that is read in the section...like I said I don't need it because it is a patch and the registry key correctly points to the location I need it to.
Afrow UK
22nd January 2008 13:39 UTC
You need to use !define MUI_DIRECTORYPAGE_VARIABLE $Var
Otherwise it will use $INSTDIR.
Stu