- NSIS Discussion
- read/write registry version & $INSTDIR
Archive: read/write registry version & $INSTDIR
bl4d3
26th July 2007 18:27 UTC
read/write in registry the version & $INSTDIR
hello,
i've created my own nsis installer for my program. but i don't know how to set a registry value with the corresponding version number and installation path.
i plan to add in future for my program an extension. the installer for the extension should check in the registry the path i have set with the main program installer.
The main installer should set these entries:
[HKEY_LOCAL_MACHINE\Software\${APPNAME}\]
"Path"="C:\Program Files\APPNAME"
"Version"="1.0" ;for future patches e.g.
And the installer for the extension should read:
[HKEY_LOCAL_MACHINE\Software\${APPNAME}\]
"Path"="C:\Program Files\APPNAME"
and set automatically on installation the path he found in the registry, to avoid mistakes in choosing the correct installation directory.
cause the customer could choose another install directory in the main installer.
i think i must use "ReadREGDWORD" and "WriteRegDWORD", but i'm not very sure about this. the solution shouldn't be very complex. something easier will do it for myself.
thank you
Red Wine
26th July 2007 18:40 UTC
That's too short, could you provide some details about your query?
bl4d3
26th July 2007 18:59 UTC
Originally posted by Red Wine
That's too short, could you provide some details about your query?
ups, sorry for that. when i wrote my text i accidentally press the
"enter"-key.
sorry.
bl4d3
26th July 2007 19:11 UTC
hm,
i think in the main installer i should use:
WriteRegStr HKLM "Software\APPNAME" "Path" "$INSTDIR"
WriteRegStr HKLM "Software\APPNAME" "Version" "${VERSION}"
and the extension installer should use:
ReadRegDWORD $0 HKLM Software\APPNAME Path
this was copied from the nsis user manual
but if this is correct, how to lock and change in the extension installer the installation directory?
Red Wine
26th July 2007 19:31 UTC
Function .onInit
ReadRegStr $0 HKLM "Software\APPNAME" "Path"
StrCpy $INSTDIR "$0"
........
FunctionEnd
Afrow UK
26th July 2007 20:14 UTC
No need for using ReadRegStr, you can just use InstallDirRegKey.
Stu
bl4d3
28th July 2007 05:50 UTC
hi,
sorry guys, but i do some bugfixing stuff on my program first, before i get time for testing the code posted here.
the code you guys have written is perfect for me.
this is how i do it and it is 100% working. i've decided to post the hole code again as i used it, to make it more understandable for others.
In the main installer write:
!define VERSION "1.0"
!define APPNAME "Your Programs Name"
Function .onInstSuccess ;After installation success the installer writes some values to registry
WriteRegStr HKLM "Software\${APPNAME}" "Path" "$INSTDIR"
WriteRegStr HKLM "Software\${APPNAME}" "Version" "${VERSION}"
FunctionEnd
and in the extension installer:
Function .onInit
ReadRegStr $0 HKLM "Software\${APPNAME}" "Path"
StrCpy $INSTDIR "$0"
FunctionEnd
big thanks goes out to all genius guys!
bl4d3
28th July 2007 20:45 UTC
hi,
there's another problem. i want to compare the version, which is stored in registry, for future patches. i've experiment with some possibilities, but ther is always an error on compiling.
patch installer:
!define NEWVERSION "v1.2"
!define CURRENTVERSION ""
...
...
!include "WordFunc.nsh"
!include "StrFunc.nsh"
${StrStr} ;Activate the StrStr Function
!insertmacro VersionCompare
Section
ReadRegStr $0 HKLM "Software\${APPNAME}" "Version"
StrCpy $CURENTVERSION "$0"
${VersionCompare} "${CURENTVERSION}" "${NEWVERSION}" $R0
${If} $R0 = 0
MessageBox MB_VER "equal"
Abort
${If} $R0 = 1
MessageBox MB_VER "newer"
Abort
${If} $R0 = 2
MessageBox MB_VER "newer"
Abort
SectionEnd
(Example: E.3.16 VersionCompare)
With those code the compiler says:
!insertmacro: end of FUNCTION_STRING_StrStr
!insertmacro: VersionCompare
!insertmacro: end of VersionCompare
Section: ""
ReadRegStr $0 HKLM\Software\APPNAME\Version
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in script "stdin" on line 85 -- aborting creation process
without those lines
ReadRegStr $0 HKLM "Software\${APPNAME}" "Version"
StrCpy $CURENTVERSION "$0"
the compiler says:
!insertmacro: end of FUNCTION_STRING_StrStr
!insertmacro: VersionCompare
!insertmacro: end of VersionCompare
Section: ""
!insertmacro: VersionCompareCall
!insertmacro: end of VersionCompareCall
!insertmacro: _If
!insertmacro: end of _If
Usage: MessageBox mode messagebox_text [/SD return] [return_check label_to_goto_if_equal [return_check2 label2]]
mode=modeflag[|modeflag[|modeflag[...]]]
modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_USERICON|MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT
Error in script "stdin" on line 88 -- aborting creation process
you see there are some bugs, but i don't know how to fix it. i'm not really fit in nsis.
thanks for help
demiller9
28th July 2007 23:24 UTC
You missed the distinction between variables (and how they are referenced) and defined constants (and their usage).
Var something
StrCpy $something "any text"
!define something "different text"
StrCmp $something ${something} equal
...
equal:
!define sets a compile time value and replaces the ${} entry with the defined value during the compilation.
Var creates a variable which only has a value after the compile, during the execution.
In addition, I think VersionCompare won't like the "v" you put in ${NEWVERSION}.
Don