Archive: Locate and pass a reg key value?


Locate and pass a reg key value?
Hi my Problem is simple.

I want read path string from the Registry and pass it over to the install path.

Say I have already an App installed and now I want to install additional documents into the "docs" folder
Now I want the setup to detect the product location from the reg key. So the user doesnt have to select the install path by himself.

Example:

In HKEY_LOCAL_MACHINE\SOFTWARE\[Product]\ there is a key telling me where the [Product] is installed. ( Say a value like "C:\Product\" is written in "Product_Path")

I want to extract that value from the reg key "Product_Path" and sort of "paste" it into the InstallDir ( like InstallDir "$detect\docs". So the Setup would automatically detect the path of my already installed product and just add files into product's directory.

I tried this:

Section GetPath
ReadRegStr $detect HKLM "SOFTWARE\Product\" "Product_Path"
SectionEnd

InstallDir "$detect\docs"

But it seems not to work :(

Please help me.


Try $INSTDIR var, NSIS Manual 4.2.2


StrCpy $INSTDIR "$detect\docs"

didnt work

I tried even with global variable but it didn't work.
where is the .onInit

and where is the $INSTDIR var specified


If I understand your question:

Read about and try:
InstallDirRegKey

(Most of the ModernUI examples use InstallDirRegKey, and also check the "non-modern" example2.nsi)

The .onInit function is called before your installer gets going. You can do quite a bit of initialization there.


Function .onInit
SetRebootFlag false
ClearErrors
ReadEnvStr $SwordPathFolder SWORD_PATH
ReadRegStr $WordPadExePath HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WORDPAD.EXE" ""
ExpandEnvStrings $WordPadExeExpPath $WordPadExePath
FunctionEnd

Function .onInstSuccess # called after installer finished
Exec '"$INSTDIR\MyApp.exe"'
FunctionEnd

Thanks.

InstallDirRegKey helped. :)


sample code.............:-)
hey alcasar, could u plz provide me tat sample code to get the installation path using InstallDirRegKey. i'm facing the same issue here.


I used the Basic.nsi example in the ModernUI folder and just modified this line:

InstallDirRegKey HKCU "Software\Modern UI Test" ""

into something like

InstallDirRegKey HKCU "Software\MyProduct" "ProductPath"


Just for completeness ... don't overlook that you have to set the registry entry that InstallDirRegKey will be referencing ... it isn't automagically done.

This can typically be done in a required [RO] section (see example2.nsi).


WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"