- NSIS Discussion
- Checking Registry
Archive: Checking Registry
TonyDS
22nd July 2003 20:30 UTC
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
22nd July 2003 21:39 UTC
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
22nd July 2003 22:37 UTC
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
22nd July 2003 23:49 UTC
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
23rd July 2003 01:00 UTC
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
23rd July 2003 12:50 UTC
Anymore help would be appreciated :)
kichik
23rd July 2003 13:01 UTC
To abort the installation from .onInit use the Abort instruction.
TonyDS
23rd July 2003 20:34 UTC
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 :up:
Comm@nder21
25th July 2003 13:56 UTC
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
25th July 2003 14:01 UTC
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.
Comm@nder21
25th July 2003 14:03 UTC
ok. im updating.
but this IS the exact error, the 3 points only stand for the filename.
kichik
25th July 2003 14:05 UTC
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
25th July 2003 14:07 UTC
hmm, above theres that:
Usage: ReadRegStr $(user_var: output) rootkey subkey entry
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)
kichik
25th July 2003 14:13 UTC
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.
Afrow UK
25th July 2003 14:35 UTC
Shouldn't it be
!define BFDIR $R9?
Or is this using the variables plug-in?
-Stu
Comm@nder21
25th July 2003 14:38 UTC
no.
other custom variables r working correctly.
and whats that with those $Rx variables??
kichik
25th July 2003 14:41 UTC
$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
25th July 2003 14:44 UTC
hmm, nothing just works.
ive updatet the compiler, and defined it as $R1 and $R9 but always the same error.
Vytautas
25th July 2003 14:49 UTC
kichik is it better, faster or more efficient to use the standard variables, $0..9 etc., rather than the new user defined vars?
Vytautas
Afrow UK
25th July 2003 14:50 UTC
So Kichik, I can use anything with $ in front of it now as variables?
-Stu ???
kichik
25th July 2003 14:51 UTC
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
25th July 2003 14:52 UTC
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
25th July 2003 14:52 UTC
OMG!
That is great Kichik, I never knew it was possible to define variables now...
Damn, somone needs to update the docs >:p
-Stu :)
Afrow UK
25th July 2003 15:01 UTC
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 :p
Comm@nder21
25th July 2003 15:04 UTC
thx very much, guys!
it's now working correctly.
and $MODPATH doesnt have to be defined as var. it works with !definde $MODPATH.
kichik
25th July 2003 15:09 UTC
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
25th July 2003 15:10 UTC
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
25th July 2003 17:03 UTC
ive got none errors with that code:
!define $MODPATH "abc"
$INSTDIR "C:\$MODPATH"
ok, not the original entries, but it looks like them.
Vytautas
26th July 2003 01:18 UTC
Yes that will work but you won't be able to modify $MODPATH after it's initial definition.
Vytautas
Comm@nder21
26th July 2003 18:07 UTC
right. but it needn't to be modified this time :D
later, i want to read out a file for this variable, but only at compile time, so, same like definition but through an external file instead of this scripted line.