Page 1 of 1 1
Topic Options
#190376 - 2008-10-29 08:38 PM Checking if a sub key exists under "windows messaging subsystem"
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
Hi Guys,

Im Brand new to scripting full stop, not just kix.......bare with me :-)

Im trying to check if any keys exist under HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles.

Its driving me round the bend because i cant work it out. its easy to check to see if a key exists if you know what key your searching for by using keyexist, but what if you dont know what the key is called??

EG:
if keyexist("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\*")
? "do this"
else
? "do this"
endif

if im being stupid please ask for my email address and send abuse at your leisure.

Thanks :-)

Top
#190378 - 2008-10-29 08:45 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Reg_D]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
EnumKey?

Check the manual for details and an example. You just use an index pointer and loop till you get an error indicating there's no more data.

(we can abuse you here, just like everyone else) \:\)

Welcome to KORG, btw. You'll get used to the abuse and teasing... return it freely as long as it's good natured!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190379 - 2008-10-29 08:49 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Actually, it's a bad example..
 Code:
$Index = 0
$KeyName = ENUMKEY('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\', $Index)
While Not @ERROR
    'Subkey found: ' $KeyName ?
    $Index = $Index + 1
Loop

Is better.. no GOTOs, single quotes, no vars in strings, etc..

Of course, you should substitute the "Subkey found" line with the code that you want to use on the subkeys in $KeyName.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190381 - 2008-10-29 09:01 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Glenn Barnas]
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
i looked at enumkey, but it kept confusing me. what i kept trying to do never worked, i loooked at the example on the kix reference section and tried to adapt. I.e,

$Index = 0
:Loop1
$KeyName = ENUMKEY(("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\", $Index)
If @ERROR > 0
$nokey = yes
else
if @error = 0
? "Profile exists: $keyname"
$Index = $Index + 1
goto Loop1
Endif

if $nokey = yes
writevalue(".....
writevalue(".....
endif


probably complete rubbish!! but trying to get to grips with understanding it.

Teasing and abuse i can deal with, Im twelve years plus younger than the rest of my team at work...... thick skinned i have become!! :-)

Thanks again, and for the quick reply

Top
#190382 - 2008-10-29 09:07 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Reg_D]
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
its more if keys are found i want it to do nothing, if they arent found i want to write registry values.

Make sense??

Cheers

Top
#190384 - 2008-10-29 09:14 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Reg_D]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
LOL - Take another look at my example adapted from the manual.

It tries to enumerate a key - if there is no error, it continues into the loop, because no error indicates a key was found. Leverage that concept..
 Code:
$DontCare = ENUMKEY('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\', 0)
If @ERROR
  ; no subkeys were found - do stuff!
Else
  ; found at least 1 subkey - everything's cool
EndIf

With this, if no keys are found at the first (0) index, it returns an error and you need to do your deeds, right? \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190385 - 2008-10-29 09:25 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Glenn Barnas]
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
well thats what ive wasted the last 2 days trying to do...... me, stupid......yes!!

i think the bit thats throwing me off is the 0 bit. is the zero saying if there is no value other than the 0 then do something, but if there is a value of "something" other than the 0 do something else??

sorry, i just like to know how and why things work rather than accept they work....

Top
#190386 - 2008-10-29 09:48 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Reg_D]
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
Gonna get me a kix manual me thinks.

your help was much appreciated Glenn. no doubt ill darken your screen again soon.

:-)
Adam

Top
#190387 - 2008-10-29 10:06 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Reg_D]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
When I went to IBM school many (many...) years ago, they taught me the first rule of computing -
"Always start counting from zero, except when you start from one."

In other words.. if you're counting computer things, the first "thing" is "thing-0", otherwise it's "thing-1". First byte=0, first watermelon=1, but you still have one of each.

ERROR 0 means "no error, or Success!", any other value means some error occurred, so "If @ERROR" will do things if any error occurred.

The EnumXXX commands want an index, and since these are computer "things", the first index is what??? Zero! The first example incremented the $Index variable so you could work through the subkeys. Since you don't care if there are subkeys, only if there AREN'T subkeys, you just need to check the first index (0) and get back an error to know there's work to be done.

Glenn

BTW - the "manual" is on the home page of the site - be sure to put it back when you're done. \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190391 - 2008-10-29 11:14 PM Re: Checking if a sub key exists under "windows messaging subsystem" [Re: Glenn Barnas]
Reg_D Offline
Fresh Scripter

Registered: 2008-10-29
Posts: 12
That makes sense, thanks for sorting that out for me. think my head goes in a spin after a while.

have finished the script i needed thanks to you. testing tomorrow :-)

I hope there are no time limit or overdue fees incurred in borrowing it......im going to be needing it for quite a while!!! :-D

Again Glenn much appreciated. nice to have a community of people to fall back on like yourselves.

Take care

Adam

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 346 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.029 seconds in which 0.01 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org