Archive: Check if Registry Key exists or not


Check if Registry Key exists or not
Hi. I want to make an installer that applies some patches on the users's system. But first I need to check what is the latest patch applied on the system. I wrote this code but it doesn't seem to work:
Function GetVMPRversion
Push $R0
ClearErrors
ReadRegStr $R0 HKLM "${versionPRpath}" "${versionPRkey}"
IfFileExists $R0 Yeah Nope
Yeah:
StrCmp $R0 "PR1" equalYES equalNO
equalYES:
Detailprint "Point Release 1 found on the system..."
equalNO:
Detailprint "Point Release 1 NOT found on the system..."
Goto exitCheck
Nope:
Detailprint "No Point Release found on the system..."
Goto exitCheck
exitCheck:
FunctionEnd

In my case this key exists (versionPRkey), but it always tells me that "No Point Release found on the system...". What am I doing wrong?


You need a Goto after equalYES
At the moment it's doing equalYES and then continuing to do equalNO as well.

You could also just replace this:
StrCmp $R0 "PR1" equalYES equalNO
equalYES:
with
StrCmp $R0 "PR1" 0 equalNO

Similarely, you don't need
Goto exitCheck
right at the end.

-Stu


I changed the code:
Function GetVMPRversion
Push $R0
ClearErrors
ReadRegStr $R0 HKLM "${versionPRpath}" "${versionPRkey}"
IfFileExists $R0 Yeah Nope
Yeah:
StrCmp $R0 "PR1" equalYES equalNO
equalYES:
Detailprint "Point Release 1 found on the system..."
Goto exitCheck
equalNO:
Detailprint "Point Release 1 NOT found on the system..."
Goto exitCheck
Nope:
Detailprint "No Point Release found on the system..."
exitCheck:
FunctionEnd

But still I get the same output: "No Point Release found on the system...". Anyone have any ideas what is wrong?


Why

IfFileExists
Maybe IfErrors?

You might have spaces in the path/file name. Try putting quotes around $R0 like this:


IfFileExists "$R0" Yeah Nope


If that doesn't do it, then you've probably got an invalid path/file name (or perhaps you simply do not have rights to location). As a troubleshooting step, you might want to temporarily insert a message box to actually see what $R0 is returning like this:


ReadRegStr $R0 HKLM "${versionPRpath}" "${versionPRkey}"
MessageBox MB_OK "Value of $$R0: [$R0]"
IfFileExists $R0 Yeah Nope

(The brackets around $R0 in the MessageBox statement will help you see whether or not there are any spaces in the file name or path)

Hope this helps!
:p

Thanks for your help. I tried with IfErrors and it worked. But still I don't know why it didn't worked with IfFileExists.


Surely if $R0 is "PR1" then why should you check that it exists with IfFileExists???
IfFileExists will check if a file exists. "PR1" is neither a file nor a path!

-Stu