#168223 - 2006-09-21 10:14 PM
KiXtart Learning Series - Lesson 01
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
In response to this post I've come up with a very mini challenge OT (off)/ OT (on) : Golfing / Minigolf http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=168388
RULES
- No KiXtart.org Moderators or Administrators aside from myself are allowed to post in this thread.
- (This is for those with less experience to learn, not for bored, experienced users to bump their post count)
- (If you're able to easily do this task then please don't participate with any solutions)
- (If the task is too easy then I'll increase the difficulty level next time)
- No using IM,PM or Google to locate/find an answer (you're on the honor system here).
Objective: Check if registry key contains an expected value of "Enterprise Terminal Server"
Using REGEDIT.EXE create the key Golfing under HKEY_CURRENT_USER\Software Then under the new Golfing key create a new Multi-String Value named Round1 and enter the following value. Enterprise {press enter key} Terminal {press enter key} Server {press enter key}
Now using KiXtart check if that value exists or not.
DO NOT Post any solution for this though until Friday, Sep 22
|
Top
|
|
|
|
#168224 - 2006-09-22 12:57 AM
Re: Mini-Golf Round 01
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
For those that want an easy method to create the key I've provided a .REG file you can download and run to create the key for this objective.
Download golfing.reg
|
Top
|
|
|
|
#168225 - 2006-09-22 02:18 AM
Re: Mini-Golf Round 01
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Doc, Could you clarify, do you want this as a code snippet or a function?
|
Top
|
|
|
|
#168227 - 2006-09-22 10:16 AM
Re: Mini-Golf Round 01
|
Björn
Korg Regular
Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
|
When are we ok'ed to post timewise? it's friday, and I think I've got it
|
Top
|
|
|
|
#168231 - 2006-09-22 07:12 PM
Re: Mini-Golf Round 01
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Code:
Dim $SO,$Re ,$R, $S, $J
;Script Options $SO=SETOPTION("Explicit", "ON") $SO=SETOPTION("NoMacrosInStrings", "ON") $SO=SETOPTION("NoVarsInStrings", "ON") $SO=SETOPTION("WrapAtEOL", "ON") BREAK ON
;Read the value at the given location $R = ReadValue("HKCU\Software\Golfing","Round1")
;Split the value as a Reg_Multi will include the | character $S = Split($R,"|")
;Now take each of the elements and put them back together ;with a space to check the value = what we want $J = Join($S," ")
;Does it match? If $J = "Enterprise Terminal Server ";space added at end as the join adds one ? "We have a match. The string returned was: " $J Else ? "No match found. The string returned was: " $J EndIf
;The value of $J was verified by printing out each of the elements of ;$S Array with the following code
/*
For $ = 0 to Ubound($S) ? $S[$] Next
*/
;When attempting to do the join, with the optional "count", it did not work. ;I was unable to determine why the following would not work
/* $J = Join($S," ",Ubound($s)-1) */
;To make this more robust one should verify that the value exist first ;then they should read the value type and write a routine to know how the ;expected return is going to be formatted, by no means should the following ;snippet be deemed fully functional, one would need to evaluate the returns ;of the different data types and build the appropriate "CASE" statement for ;that scenario
;Example
/*
If KeyExist("HKCU\Software\Golfing\Round1") = 1 $Type = Readtype("HKCU\Software\Golfing","Round1") $R = ReadValue("HKCU\Software\Golfing","Round1") Select Case $Type = "Reg_Multi_SZ" $S = Split($R,"|") $J = Join($S," ") Case $Type = "Reg_SZ" $J = $S Case 1 @Error = 5 EndSelect
Else Exit 1 EndIf
*/
|
Top
|
|
|
|
#168232 - 2006-09-22 07:39 PM
Re: Mini-Golf Round 01
|
PaulyT
Fresh Scripter
Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
|
I had two solutions.
Solution 1 Code:
$ = ReadValue('HKCU\Software\Golfing', 'Round1') Do $ = SubStr($, 1, InStr($, '|') - 1) + ' ' + SubStr($, InStr($, '|') + 1, Len($)) Until InStr($, '|') = 0 If Rtrim($) = 'Enterprise Terminal Server' ? 'Value Present' EndIf
Solution 2 Code:
$ = Split(ReadValue('HKCU\Software\Golfing', 'Round1'), '|') For Each $a in $ If InStr('Enterprise Terminal Server', $a) = 0 Exit EndIf Next ? 'Value Present'
|
Top
|
|
|
|
#168236 - 2006-09-22 10:11 PM
Re: Mini-Golf Round 01
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
|
Top
|
|
|
|
#168237 - 2006-09-22 10:51 PM
Re: Mini-Golf Round 01
|
Björn
Korg Regular
Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
|
Well, took some time to get to work again, but here it is, one warning - it's long
Code:
/* Minigolfing 01*/
If NOT @LOGONMODE Break On EndIf
Dim $SO,$Key,$wr $SO = SetOption("Explicit","On") $SO = SetOption("NoVarsInStrings","On") $SO = SetOption("NoMacrosInStrings","On")
$key='HKEY_CURRENT_USER\Software\','Golfing','Round1','Enterprise Terminal Server' ;The first two is the key, third is the value, and forth the data we are looking for.
$wr=FindMe($key) ; will return a code to @error: 0 for true, and 1 for not true @error
Function FindMe($key) Dim $ch,$found,$index,$valuename,$KeyF,$JoinKey,$Valuename2,$wr,$split,$inst $ch=KeyExist($key[0]) ; Does the HKEY_CURRENT_USER_\Software\ exist? if $ch ;If it does.... $found=0 $index=0 ;Setting values so the while-statement will not run forever..
while @error=0 and $found=0 ;While no errors and $found is still 0 $ValueName = ENUMKEY($key[0],$index) ;Lists the subkey, $index points to the 'number' in the list if $ValueName = $Key[1] $found=1 ;If the subkey is the same as the $Key[1] (second val in array), $found is set to 1 $KeyF=$key[0],$ValueName ;make an array out of $Key[0] and $ValueName $JoinKey=Join($KeyF,'') ;Join 'em together $wr=ReadValue($JoinKey,$Key[2]) ;Reads the data of value in the key $split=Split($wr,'|') ;Current format is seperated by '|', therefore remove those $wr=Join($split,' ') ; and join 'em together $inst=Instr($wr,$Key[3]) ;Does $wr contain the same as $Key[3] ? if $inst exit 0 else exit 1 endif ; If it does, exit with a 0, otherwise exit with a 1 else $Index = $Index + 1 ;$ValueName wasn't the same as $Key[1], continues to look for matches. endif loop exit @error ; In case of an unexpected error comes along, just exit with it (dunno if really needed)
endif
EndFunction
|
Top
|
|
|
|
#168238 - 2006-09-22 10:53 PM
Re: Mini-Golf Round 01
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
My second piece was not meant to be functional and was never tested. However at your request...
Code:
Dim $Type, $S, $J, $R
If KeyExist("HKCU\Software\Golfing") = 1 $Type = Readtype("HKCU\Software\Golfing","Round1") $R = ReadValue("HKCU\Software\Golfing","Round1") Select Case $Type = "Reg_Multi_SZ" $S = Split($R,"|") $J = Join($S," ") Case $Type = "Reg_SZ" $J = $R Case 1 @Error = 5 EndSelect If $J = "Enterprise Terminal Server ";space added at end as the join adds one ? "We have a match. The string returned was: " $J Else ? "No match found. The string returned was: " $J EndIf
Else Exit 1 EndIf
|
Top
|
|
|
|
#168239 - 2006-09-22 10:54 PM
Re: Mini-Golf Round 01
|
Björn
Korg Regular
Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
|
Nice going Garg! You acctually added what I was thinking about - what kind of entry it was! I see some similarities in our code
|
Top
|
|
|
|
#168240 - 2006-09-22 10:55 PM
Re: Mini-Golf Round 01
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
To much time around the likes of Doc and Jooel can do that to you.
|
Top
|
|
|
|
#168242 - 2006-09-22 11:02 PM
Re: Mini-Golf Round 01
|
Björn
Korg Regular
Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
|
Garg - you've got a message! Doc, well.. urhnm, you know how my 'coding' is
|
Top
|
|
|
|
Moderator: NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen
|
0 registered
and 565 anonymous users online.
|
|
|