Archive: read key and action if have a value


read key and action if have a value
i have a product in two part, i can install separately in two computer but if i install on same computer, in install section i need to read a key read said me the path where one of my part had installed and after i use this path in directory page of install. If this key is not present i use the path by default.
my problem is: i don't know use the function if in NSIS.

my key
ReadRegStr HKCU "Software\${MUI_PRODUCT}\part1" "" ${pathpart1}
and if not present, i want to use InstallDir "$PROGRAMFILES\${MUI_PRODUCT}

i have the same problem in uninstall section a want to read a key, if a key is present i don't want delete the main folder, and if is not present i want to call a fonction who uninstall another product.
thanks for your help


Not exacly certain about the uninstall part but as for the installer you should first set the $INSTDIR to the path you want to use if the other part is not installed and then use the 'InstallDirRegKey' command to overwrite the path if the specified key exists.

Vytautas


Well, firstly you set InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"

Now,
ReadRegStr $R0 HKCU "Software\${MUI_PRODUCT}\part1" "" ${pathpart1}
StrCmp $R0 "" +2
StrCpy $INSTDIR $R0

Is this what you want?

-Stu


Afrow UK, is it not easier to use 'InstallDirRegKey' function?

Vytautas


thanks for your help
i 'm trying and i said you tomorrow what solution i used.


i try this
ReadRegStr $R5 HKCU "Software\${MUI_PRODUCT}" "Pathproduct"
IfErrors 0 suite
InstallDir "$R5"
Goto next

suite:
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"
goto next

next:
InstallDirRegKey HKCU "Software\${MUI_PRODUCT}" ""

i have this error
Can't add entry, no section or function is open!

so i add this in function .oninit
now i have error
command InstallDir not valid in function.

How can i put the path what i store in registry with previous install in directory page.

i thinks i have done a bad explication.
in my product i have to part in one side i have the client and the other side i have the server. i can install server and clietn in same computer or in separately computers.
my client side is installed in a sub folder "client" (for server it s in a subfolder "server". the main folder is the product folder.
I want when i install for example my client side to put a registry key who said me where are my product, like: HKCU "Software\${MUI_PRODUCT}" "Pathproduct"
and other key with my path client like
HKCU "Software\${MUI_PRODUCT}\Client" "PathClient" in this key i have
PathProduct\client (i thinks is more easy for updtade)

Now if i install server side (or client side for update).
i want my install check if this key exist HKCU "Software\${MUI_PRODUCT}" "Pathproduct"
in directory page i want it propose the path of product and after the serverside is installed in subfoler server.
but if this key doesn't exist, the directory page propose me the default path $PROGRAMFILES\${MUI_PRODUCT}.

i hope now i have done a good explication :)
thanks


Your stuff needs to go into a section/function.

e.g. use onInit to execute your cmds on initialisation

Function .onInit
ReadRegStr $R5 HKCU "Software\${MUI_PRODUCT}" "Pathproduct"
IfErrors 0 suite
InstallDir "$R5"
Goto next

suite:
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"
goto next

next:
InstallDirRegKey HKCU "Software\${MUI_PRODUCT}" ""
FunctionEnd

-Stu


InstallDir won't work in a function to assign a path inside a function you sould use

StrCpy $INSTDIR "your_path"

Vytautas

InstallDirRegKey won't work in a function.
i tried the function but i don't use InstallDirRegKey.
in my first installation, in directory page, by defalut i have :
c:\program files\myproduct.
i choose, c:\bin\myproduct. my product(serverside) is installed in c:\bin\myproduct\server.

now if i install again server side of if i install the first installation of client side, in directory page i have again
c:\program files\myproduct and no c:\bin\myproduct.
why doctor???
thanks


You will have to make your own registry key to store the InstallDir value, instead of using InstDirRegKey.

-Stu


in the install, i had created

!define pathsrv "$INSTDIR\server"
WriteRegStr HKCU "Software\${MUI_PRODUCT}" "Pathproduct" $INSTDIR
and
WriteRegStr HKCU "Software\${MUI_PRODUCT}\server" "" ${pathsrv}

and for me the $INSTDIR is the path i have define in directory page in the first time.
but it's no good


Can you post your script so I can understand what you are trying to achieve?

-Stu


in the client side, only this variable change
MUI_PRODUCT = client
MUI_VERSION = v2.0
FOLD_INST = client
PATH_SRV = $INSTDIR\${FOLD_INST}
so i have two problem when i install the client side(or for update server side) i want the program go to read if regkey HKCU "Software\${COMPANY}" "PathComp" exist and if is good i want the directory page show me the value of this key (it's the $INSTDIR of first install) and if is not good directory page show me $PROGRAMFILES\${COMPANY}.
my other problem is uninstall, i have noticed the directory page of unistallation show me the path ${PATH_SRV}\${FOLD_INST}, so i have for example c:\program files\my company\server\server and i want c:\program files\my company\server.
thanks


Ok, heres what should be done [from what I have read].
Use in uninstall section.

ReadRegStr $R0 HKCU "Software\${COMPANY}" "PathComp"
StrCmp $R0 "" 0 is_present ;jump to

ReadRegStr $R0 HKCU "Software\${COMPANY}\${FOLD_INST}" "PathSrv"
## do stuff here for non present reg entry ##

Goto done
is_present:
## do stuff here for presnt reg entry ##

done:


I noticed this should be changed:
execwait '$SYSDIR\msiexec.Exe /i $EXEDIR\access-2000\osp.msi TRANSFORMS="$EXEDIR\access-2000\osp.MST" /qb-'


to
ExecWait '"$SYSDIR\msiexec.exe" /i "$EXEDIR\access-2000\osp.msi" TRANSFORMS="$EXEDIR\access-2000\osp.MST" /qb-'


Else, this execute would fail if $SYSDIR or $INSTDIR had spaces in it.

-Stu

thanks a lot for your help.
i hope to help you one day.