Skip to content
⌘ NSIS Forum Archive

Checking Registry

31 posts

TonyDS#

Checking Registry

Hi There,

I know it must be possible using ReadRegStr

Plus I have read the documents and searched through other topics on this matter, but they where of no help as they don't explain what script I need.

Anyhow to my question, I would to be able to create a small script within my patch scritp that before installation checks the registry to see if the game I'm patching is the correct version.

Say if it was version 1.0 the installation would abort with a message saying I need to upgrade to version 2.0, but it version 2.0 was found in the registry the installation of my patch would continue.

Any help would be grateful, including the script that would show me what I would need 🙂

Thanks

-Tony
Joel#
Try this:

ReadRegStr $0 HKLM "SOFTWARE\GameX" "Version"
IniCmp $0 1 +1 +1 +3
MessageBox MB_OK "Must upgrade, dude"
Goto +2
MessageBox MB_OK "Your Ok, dude."
TonyDS#
Didn't work I just got this error

ReadRegStr expects 4 parameters, got 5.
Usage: ReadRegStr $(user_var: output) rootkey subkey entry
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)
this is the code I used

ReadRegStr $0 HKLM "SOFTWARE\blah\blah\v1.0\" "Version"="2.0"
IniCmp $0 1 +1 +1 +3
MessageBox MB_OK "Must upgrade, dude"
Goto +2
MessageBox MB_OK "Your Ok, dude."
Oh where in the script do I add it i.e. top, bottom?

Do I need to add Function or Section?
Joel#
ReadRegStr must be inside of Section or Function.
Your error was for the "Version"="2.0" thing...
Try this little exampleFor example:

Function .onInit
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\DirectX" "Version"
StrCpy $1 $0 4 3
MessageBox MB_OK $1
Quit
FunctionEnd
TonyDS#
Ok that worked fine

I also figured out why the other script didn't work

you put IniCmp

When it should have been IntCmp with a T, sorry, I'm not complaining 🙂

Also sorted out the version thing thanks alot 🙂

Anyhow, how would I do it, if I only wanted the "Must upgrade, dude" message, if it was the wrong version, and then just quit the program after clicking OK.

If it was the right version it wouldn't show any message or any Ok button and just carry on to the License page and so on

At the moment it shows either message, you click on OK and it carries on with the program.

Thanks

-Tony
TonyDS#
Thanks I had already figured that out, before I could change my last post

Thanks to all who gave help

The installer works perfectly now 🙂

By the way guys great work keep it up 👍
Comm@nder21#
doesnt work 🙁

hi there !
ive written the following section, to read the installation path from the registry:

Section "-installdir"
!define BFDIR ""
ReadRegStr $BFDIR HKLM "Software\EA GAMES\Battlefield 1942" "GAMEDIR"
StrCpy $INSTDIR "$BFDIR\Mods\$MODPATH"
SectionEnd
InstallDir "$INSTDIR"
but i always get this error-message:
Error in script "..." on line 81 -- aborting creation process
what's wrong with that code?
is this just another bug in the compiler?

if it looks like this, it works:

Section "-installdir"
!define BFDIR ""
ReadRegStr $INSTDIR HKLM "Software\EA GAMES\Battlefield 1942" "GAMEDIR"
StrCpy $INSTDIR "$BFDIR\Mods\$MODPATH"
SectionEnd
InstallDir "$INSTDIR"
plz help me.
kichik#
What is the exact error you get? Try updating to the latest CVS version (from now), maybe it's a bug with user variables Ramon has already fixed.
kichik#
But what's the error text above it? There is usually more than one line of error, the last one just saying processing has stopped.
Comm@nder21#
hmm, above theres that:
Usage: ReadRegStr $(user_var: output) rootkey subkey entry
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)
kichik#
Ah, it doesn't recognize the variable. You need latest CVS version, it should solve it. Also make sure you define the variable using Var BFDIR and Var MODPATH.
Comm@nder21#
no.
other custom variables r working correctly.
and whats that with those $Rx variables??
kichik#
$R* are built-in registers that existed long before you could define your own.

BTW, Afrow, the new user variables are not a plug-in, they're built-in.
Comm@nder21#
hmm, nothing just works.
ive updatet the compiler, and defined it as $R1 and $R9 but always the same error.
Vytautas#
kichik is it better, faster or more efficient to use the standard variables, $0..9 etc., rather than the new user defined vars?

Vytautas
kichik#
Defined what as $R9??? Drop that !define, it shouldn't be there. The exact script should be:

Var BFDIR
Var MODPATH

Section "-installdir"
ReadRegStr $BFDIR HKLM "Software\EA GAMES\Battlefield 1942" "GAMEDIR"
StrCpy $INSTDIR "$BFDIR\Mods\$MODPATH"
SectionEnd
InstallDir "$INSTDIR"
kichik#
Vytautas, the only difference is less memory usage when you don't define your own variables. With normal makensis.exe (NSIS_MAX_STRLEN = 1024) it's another 1KB of memory for every variable.

Afrow, as long as you define it using Var, yes.
Afrow UK#
OMG!
That is great Kichik, I never knew it was possible to define variables now...

Damn, somone needs to update the docs >😛

-Stu 🙂
Afrow UK#
Argh!!!
oops...

BTW, if you ned me to update the docs when needed then I don't mind (I'm getting paid to do websites now 🙂)

-Stu 😛
Comm@nder21#
thx very much, guys!
it's now working correctly.
and $MODPATH doesnt have to be defined as var. it works with !definde $MODPATH.
kichik#
No it doesn't. ${MODPATH} is the value of the define, $MODPATH is just plain $MODPATH. You should also get a warning about MODPATH not found. If you do want $MODPATH literally (doubt you do, it's in a path), you need to write it with double dollar sign: $$MODPATH.
Afrow UK#
For compile time constants:
!define MODDIR "C:\quake2\dday"

Then, you can do stuff in your script like so:
CopyFiles "$TEMP\blah\*.*" ${MODDIR}

Changeable variables should be set using:
Var MODDIR

-Stu
Comm@nder21#
ive got none errors with that code:

!define $MODPATH "abc"
$INSTDIR "C:\$MODPATH"

ok, not the original entries, but it looks like them.
Vytautas#
Yes that will work but you won't be able to modify $MODPATH after it's initial definition.

Vytautas