Shoutbox

does a registry string exhist - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: does a registry string exhist (/showthread.php?tid=62049)

does a registry string exhist by JonnyT on 06-29-2006 at 07:11 PM

i know the registry options are limited but is tere away to find out if a certain string exhists? Im doing this becuase the script chucks out an error if i try to read from a string tht doesnt exhist.

Thanks jon


RE: does a registry string exhist by L. Coyote on 06-29-2006 at 07:18 PM

I use this to check if a key exists.

It returns true if it does, and false if it doesn't exist.

Btw, it doesn't check for a value, just a key. But you can modify it. Instead of "return true", make it "return tmp" and check the returned value with whatever you want.

code:
function isreg(path) {
var reg, tmp;
  try {
  reg = new ActiveXObject("WScript.Shell");
  tmp = reg.RegRead(RegUserPath + path);
   if(tmp != "") return true;
  } catch(e) {
  return false;
  }
}


This is just a workaround, not a real solution, but it works and prevents the script from returning an error.

You can read more of try...catch...finally in the MSDN library.



quote:
Originally posted by RaceProUK
quote:
Originally posted by Leonardo
if(tmp != "") return true;
:dodgy:
code:
return tmp != "";

Oh, genious. :rolleyes:

Seriously people, is there a difference? Except from saving 0.00001 second and a couple of bytes, is there really a difference? No? Then, let it go. :dodgy:

RE: does a registry string exhist by matty on 06-29-2006 at 07:31 PM

http://mattyg.ca/geshi/registry.php

My registry module has KeyValueExist among other functions

CreateKey
DeleteKey
DeleteKeyValue
KeyExist
SetDWordValue
SetStringValue
GetDWordValue
GetStringValue

Will be including an EnumRegistryKeys and possibly Get/Set Binary keys.


RE: does a registry string exhist by RaceProUK on 06-29-2006 at 09:36 PM

quote:
Originally posted by Leonardo
if(tmp != "") return true;
:dodgy:
code:
return tmp != "";

RE: does a registry string exhist by JonnyT on 06-29-2006 at 09:43 PM

thanks matty your scripts worked great :D


RE: RE: does a registry string exhist by CookieRevised on 06-29-2006 at 10:38 PM

quote:
Originally posted by Leonardo
Seriously people, is there a difference? Except from saving 0.00001 second and a couple of bytes, is there really a difference? No? Then, let it go. :dodgy:
yes there is a difference. and "return tmp != "";" is prefereable.

Moreover, checking if tmp is empty isn't a good thing todo as keys can also be empty (yet existing). That line should actually just be "return true".
RE: does a registry string exhist by L. Coyote on 06-29-2006 at 10:57 PM

I already said in that post of mine, that if the person wants to directly return the string, then they simply change that part.

As for the empty string, true. But that function is specifically done for that purpose. I just kindly gave it out as an example.

:^) This all makes me think I shouldn't be that kind after all, seeing everytime I do someone complains about my coding, or simply steals it.

* L. Coyote learns from mistakes. :D


RE: does a registry string exhist by RaceProUK on 06-30-2006 at 11:48 AM

quote:
Originally posted by Leonardo
:^) This all makes me think I shouldn't be that kind after all, seeing everytime I do someone complains about my coding, or simply steals it.
Get over it already! I'm actually slightly offended that you think I complain about other people's code: I don't, I suggest improvements. And I expect people to suggest improvements to my code.