Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 25th July 2003, 23:25   #1
jcagle
Senior Member
 
Join Date: Jul 2003
Posts: 103
IfKeyExists??

Is there a built-in function for "IfKeyExists"? If not, I think I'm going to attempt to make a function for that...and maybe others would like it as well. But, remember, I'm a beginner, so my way may not be the best way......it will just be A way. Thanks!
jcagle is offline   Reply With Quote
Old 25th July 2003, 23:30   #2
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
No I don't think that there is a function for this. You might find EnumRegKey usefull in creating that function.

Vytautas

BTW If you need any help in creating it just ask
Vytautas is offline   Reply With Quote
Old 26th July 2003, 01:46   #3
jcagle
Senior Member
 
Join Date: Jul 2003
Posts: 103
I looked into creating IfKeyExists, but it looks like it's only worth making if it can be a built-in function...like IfFileExists...at least from what I know.

In other words, WITHOUT being a built-in function, the call would look like this:
Push $0
Push $1
Push $2
Push $3
Push $R0 'Return Value
Call IfKeyExists
Pop $3
Pop $2
Pop $1
Pop $0
StrCmp $R0 "" 0 ItExists
MessageBox "Key Does Not Exist"
GoTo Done
ItExists:
MessageBox "Key Exists"
Done:
Pop $R0

Or, you could simply use (I think this is how it's used):
Push $R0
EnumRegKey $R0 HKCU "Software\Package" "Version" "0"
StrCmp $R0 "" 0 ItExists
MessageBox "Key Does Not Exist"
GoTo Done
ItExists:
MessageBox "Key Exists"
Done:
Pop $R0

OR...if it were built-in:
IfKeyExists HKCU "Software\Package" "Version" 0 ItExists
MessageBox "Key Does Not Exist"
GoTo Done
ItExists:
MessageBox "Key Exists"
Done:

What does everyone else think???
jcagle is offline   Reply With Quote
Old 26th July 2003, 02:45   #4
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
I created a macro to do this, well almost, you can find it here. After you insert this macro you should pop the result of the stack and check to see if it was found.

I tried to create a macro which can jump to a label depending on the result however I could not figure out how to make the last parameter of the macro optional, any ideas?

Hope this helps, BTW your code for EnumRegKey would not work, it will generate an infinate loop, you should increment the index every time you check for the next key.

Vytautas
Vytautas is offline   Reply With Quote
Old 26th July 2003, 10:35   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
There's an error.
You have used Found for a jump instead of FoundMe

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th July 2003, 10:39   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
What do yo umean by this?

I tried to create a macro which can jump to a label depending on the result however I could not figure out how to make the last parameter of the macro optional, any ideas?

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th July 2003, 12:23   #7
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
I tried this code and it worked but only if both labels are specified
code:
!insertmacro IfKeyExists "ROOT" "KeyToCheckIn" "KeyToCheck" "GOTO_Here_IF_FOUND" "GOTO_Here_IF_NOT_FOUND"
I would like the last label to be optional like in similar function calls.

Vytautas
Vytautas is offline   Reply With Quote
Old 26th July 2003, 12:26   #8
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Quote:
Originally posted by Afrow UK
There's an error.
You have used Found for a jump instead of FoundMe

-Stu
Thanks, fixed that error.

Vytautas
Vytautas is offline   Reply With Quote
Old 26th July 2003, 12:42   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Ah I don't really know.
I didn't even know you could do jumps with InsertMacro's!

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th July 2003, 12:50   #10
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
I'm not sure you're supposed to but I tried and jumps to labels seemed to work. Relative jumps would need heavy modification so probably are not a good idea. You see the jumps work because !insertmacro code just does a copy&paste of the macro into the script, not literally but effectively.

Vytautas
Vytautas is offline   Reply With Quote
Old 26th July 2003, 15:10   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Ah yes I was thinking about that.
Also, surely if you wanted people to use your code more than once in the same script then you should gave each label a specific name eg.

FoundMe${BLAH}

Have a look at how Modern UI uses Macro's and maybe that will help you find it out.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 27th July 2003, 04:18   #12
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Thanks, I didn't think to test this macro more than once in the script.

Vytautas
Vytautas is offline   Reply With Quote
Old 27th July 2003, 15:51   #13
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
Quote:
Is there a built-in function for "IfKeyExists"?
Wouldn't this do the job?
PHP Code:
ClearErrors
ReadINIStr 
$"$EXEDIR\\Settings.ini" "Settings" "Search String"
IfErrors "" cont
MessageBox MB_OK 
`problems, problems!`
cont
changing the ini for the registry
n0On3 is offline   Reply With Quote
Old 27th July 2003, 23:10   #14
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Not quite, your solution will work with values NOT keys.

Vytautas
Vytautas is offline   Reply With Quote
Old 28th July 2003, 11:49   #15
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
keys means branches, isn't it?

in that case you can check for the default value every key has, isn't it?
n0On3 is offline   Reply With Quote
Old 28th July 2003, 12:20   #16
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Yes, but most registry keys have blank, not set, dafault values so that function would not find those keys.

Vytautas
Vytautas is offline   Reply With Quote
Old 30th July 2003, 02:24   #17
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
mmmm... I suppose that blank default values don't set the error flag to true.

mmmm... I tested with this existant and empty key and doesn't report an error
PHP Code:
  ClearErrors
  ReadRegStr 
$5 HKCR ".art\\ShellEx" ""
  
Iferrors "" noter
    MessageBox MB_OK 
"error"
  
noter

Last edited by n0On3; 30th July 2003 at 02:41.
n0On3 is offline   Reply With Quote
Old 30th July 2003, 02:55   #18
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
I tried both your code and the following code to a key that does not exist and both showed the message box.
code:
ClearErrors
ReadRegStr $5 HKCR ".art\ShellEx.test" ""
Iferrors "" noter
MessageBox MB_OK "error"
noter:

It seems to me that the error flag is set if the value is not set and also if the value does not exist and is therefore not very usefull for the function we need here.

Vytautas
Vytautas is offline   Reply With Quote
Old 30th July 2003, 18:02   #19
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
oh, I don't understand now.

In my computer if the "(Default)" value is "(value not set)" then the messagebox it's not showed.

I am using win98se and I attach a snapshot of the registry when I use that piece of code.
Attached Images
File Type: png registry.png (8.0 KB, 371 views)
n0On3 is offline   Reply With Quote
Old 2nd August 2003, 20:58   #20
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
The error flag is set for ReadRegStr when the key can not be opened (security, not found or anything else), the value doesn't exist or can't be queried (again security, not found or anything else) or if the type of the value is wrong (not of type string).

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 18th August 2003, 19:08   #21
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
sorry, I read this many times, and can't conclude if the idea I give is valid or not.

It's still seems to me that is valid.
n0On3 is offline   Reply With Quote
Old 18th August 2003, 20:18   #22
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,351
Send a message via ICQ to deguix
This below isn't sufficient to do it? (I don't know if the code below works because I don't have a personal computer, nor NSIS)

code:
EnumRegKey $0 HKLM "Software/NSIS" 0
IfErrors 0 +3
StrCpy $0 0
Goto +2
StrCpy $0 1



Please, someone test it.

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 19th August 2003, 00:07   #23
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
deguix, the last parameter of the EnumRegKey is the index of the entry to check and thus it should be incremented otherwise it will either only check the first key or create an infinate loop.

So the last '0' should be replaced with a variables which is incremented until the required key is found or all of the keys are search through.

Vytautas
Vytautas is offline   Reply With Quote
Old 19th August 2003, 00:35   #24
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,351
Send a message via ICQ to deguix
You want to know if have keys inside the key, or want to know if it exist or not?

(hey, my signature style is being copied by some users in this forum! My signature is going to be famous by this way!)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 19th August 2003, 02:23   #25
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
So does the EnumRegKeys function return the root key before it's subkeys? I did not find that in the documentation & can not check you code at this moment. Will get back as soon as I can check it out although I dought it will work as expected.

Vytautas

PS Your idea for the signiture was really good. Thanks
Vytautas is offline   Reply With Quote
Old 19th August 2003, 03:36   #26
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
ok, I am completely lost on this subject.
n0On3 is offline   Reply With Quote
Old 19th August 2003, 13:18   #27
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Doesn't the function in my archive pages work for you???

Vytautas
Vytautas is offline   Reply With Quote
Old 13th November 2003, 19:19   #28
AnalogKid
Junior Member
 
Join Date: Jan 2003
Location: Fremont, CA
Posts: 9
Send a message via ICQ to AnalogKid
Exclamation Typo in your macro Vytautas...

Right after the EnumRegKey call you put a colon on the goto label, which causes a 'couldn't resolve the label' compile-time error.

code:

"${Index}-Loop:"
; Check for Key
EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
StrCmp $R0 "" "${Index}-False:"



that StrCmp line should read ...
code:

StrCmp $R0 "" "${Index}-False"



I like your method, but it doesn't seem to work for me -- I haven't had luck with EnumRegKey and ReadRegStr either. Here's an example where I use a key that I know exists (looking at it in RegEdit):

code:

Function Sample
!insertmacro KeyExists HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Acrobat 5.0" "DisplayName"
Pop $R0
IntCmp $R0 0 EndSample EndSample 0

;...code to handle stuff when we find the key ...
MessageBox MB_OK "Wow it found it!"

EndSample:
FunctionEnd



... I never see the dialog box, even though I know the key exists. I figure that at least 1 other person in this forum will have Acrobat 5 (reader) installed, so if you can make the above code work on your system as-is then my machine is horked somehow. If there's a mistake, please let me know where I went wrong!

NSIS 2.0b4, Win2K Pro ...

Thanks!!

AnalogKid
=^{D}
AnalogKid is offline   Reply With Quote
Old 13th November 2003, 22:02   #29
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
Quote:
Originally posted by Vytautas
Doesn't the function in my archive pages work for you???

Vytautas
Oh, sorry, I didn't read your reply. I was lost on the discussion, I haven't tried your function.

I just couldn't understand why my idea does not work.
n0On3 is offline   Reply With Quote
Old 13th November 2003, 22:20   #30
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Quote:
Right after the EnumRegKey call you put a colon on the goto label, which causes a 'couldn't resolve the label' compile-time error.
Thanks, fixed.

As for the other problem. 'DisplayName' is NOT a key, keys appear as folders in regedit, so thats why the function does not work.

Vytautas
Vytautas is offline   Reply With Quote
Old 14th November 2003, 08:00   #31
AnalogKid
Junior Member
 
Join Date: Jan 2003
Location: Fremont, CA
Posts: 9
Send a message via ICQ to AnalogKid
Yes, sorry, I figured out what was wrong right about the same time I woke up and went home ... EnumRegValue is what I really wanted rather than EnumRegKey ;-)

Thanks for the cool fn/macro and the ideas with the self-generating labels. I've never tried that before -- didn't know it would work ;-)

I love these forums ... I get so much inspiration sometimes just by glancing through 'em!

AnalogKid
=^{D}
AnalogKid is offline   Reply With Quote
Old 14th November 2003, 08:51   #32
n0On3
Senior Member
 
n0On3's Avatar
 
Join Date: Jan 2001
Location: Barcelona
Posts: 314
Send a message via ICQ to n0On3
Quote:
Originally posted by Vytautas
As for the other problem. 'DisplayName' is NOT a key, keys appear as folders in regedit, so thats why the function does not work.
I still don't understand.

code:
ClearErrors
ReadRegStr $5 HKCR ".art\ShellEx.test" ""
Iferrors "" noter
MessageBox MB_OK "error"
noter:


This checks for the "(Default)" name which something every key (folder ) has.

The only fault I can imagine is what kichik says: that the error flag could be triggered when it can't be opened because of security or can't be queried.
n0On3 is offline   Reply With Quote
Old 14th November 2003, 10:47   #33
Vytautas
Major Dude
 
Vytautas's Avatar
 
Join Date: May 2003
Location: Victoria, Australia
Posts: 643
Send a message via ICQ to Vytautas
Although every key has that entry it is not set, e.g. is Null, and therefore NSIS sets the error flag as if the entry did not exist.

Vytautas
Vytautas is offline   Reply With Quote
Old 18th April 2008, 14:41   #34
cherdeg
Junior Member
 
Join Date: Apr 2008
Posts: 16
Why doesn't this code work?

Hi,

I try to use your macro to check for a certain registry key, this is my code:

[...]
;Check if the standard Cygwin Registry keys exist (x32)
!insertmacro IfKeyExists HKLM "SOFTWARE\Cygnus Solutions\Cygwin\mounts v2" "cygdrive flags"
Pop $R0
IntCmp $R0 0 DoInstall ByReg ByReg
;Check if the standard Cygwin Registry keys exist (x64)
!insertmacro IfKeyExists HKLM "SOFTWARE\Wow6432Node\Cygnus Solutions\Cygwin\mounts v2" "cygdrive flags"
Pop $R0
IntCmp $R0 0 DoInstall ByReg ByReg

;This is the label to jump to if a registy key is found
ByReg:
MessageBox MB_ICONSTOP "RegistryKeys for Cygwin exist on this machine. Please first remove any installation of cygwin and then restart this installer..."
Quit

;This is the label to jump to if Cygwin is not installed yet.
DoInstall:
[...]

Why wouldn't it jump to ByReg if the key is found?

Please help - I'm lost...

Regards,

Chris
cherdeg is offline   Reply With Quote
Old 24th June 2012, 16:25   #35
PoRtAbLe_StEaLtH
Junior Member
 
Join Date: Jul 2011
Posts: 47
Quote:
Originally Posted by cherdeg View Post
Hi,

I try to use your macro to check for a certain registry key, this is my code:

[...]
;Check if the standard Cygwin Registry keys exist (x32)
!insertmacro IfKeyExists HKLM "SOFTWARE\Cygnus Solutions\Cygwin\mounts v2" "cygdrive flags"
Pop $R0
IntCmp $R0 0 DoInstall ByReg ByReg
;Check if the standard Cygwin Registry keys exist (x64)
!insertmacro IfKeyExists HKLM "SOFTWARE\Wow6432Node\Cygnus Solutions\Cygwin\mounts v2" "cygdrive flags"
Pop $R0
IntCmp $R0 0 DoInstall ByReg ByReg

;This is the label to jump to if a registy key is found
ByReg:
MessageBox MB_ICONSTOP "RegistryKeys for Cygwin exist on this machine. Please first remove any installation of cygwin and then restart this installer..."
Quit

;This is the label to jump to if Cygwin is not installed yet.
DoInstall:
[...]

Why wouldn't it jump to ByReg if the key is found?

Please help - I'm lost...

Regards,

Chris

you have 2 'ByReg'.

it should be:
code:
IntCmp $R0 0 DoInstall ByReg


Also.. if you're checking x64 reg key.. use SetRegView 64.
PoRtAbLe_StEaLtH is offline   Reply With Quote
Old 25th June 2012, 21:16   #36
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
And use LogicLib instead of IntCmp.

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump