Comments on Bjorn's code



If NOT @LOGONMODE
Break On
EndIf

Dim $SO,$Key,$wr
$SO = SetOption("Explicit","On")
$SO = SetOption("NoVarsInStrings","On")
$SO = SetOption("NoMacrosInStrings","On")

; Good practice setting the options, including the break on method.


; Minor observation so that other new scripters are aware
; KiXtart can use abbeviations for some of the main Registry keys


;Registry Functions
;All registry functions use the following format to specify registry subkeys:
;[\\remote_computer_name\][Key\]Subkey
;Remote_computer_name can be any valid computer name in UNC format (preceded by two backslashes).
;If you do not specify a remote_computer_name, the program defaults to the local registry.
;Key can be any of the main registry trees: HKEY_LOCAL_MACHINE (or HKLM in short),
;HKEY_USERS (HKU), HKEY_CLASSES_ROOT (HKCR), HKEY_CURRENT_USER (HKCU) or
;HKEY_CURRENT_CONFIG (HKCC). If you do not specify a root key, KiXtart will use
;HKEY_CURRENT_USER as the default.


$key='HKEY_CURRENT_USER\Software\','Golfing','Round1','Enterprise Terminal Server'

; A best practice for a production script would be to use var names that have some
; type of meaning that is easily understood.
$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

; Using $key[0] is optomistic. If a user missed a comma or similar typo the
; UDF would end abnormally.
; I'd have to think about how best to modify it without completely changing your code.
$ch=KeyExist($key[0]) ; Does the HKEY_CURRENT_USER_\Software\ exist?

; In many cases just an If $var is good enough, but be aware there are times that
; this is not sufficient and could lead to unexpected results.
if $ch

; This is along the lines of the $key[0] issue and you've set it so that there
; is a known value to start with which is good.
$found=0
$index=0 ;Setting values so the while-statement will not run forever..


while @error=0 and $found=0
$ValueName = ENUMKEY($key[0],$index)
if $ValueName = $Key[1] $found=1
; Need to be careful or at least aware of data types when concatenating data
$KeyF=$key[0],$ValueName
$JoinKey=Join($KeyF,'')
$wr=ReadValue($JoinKey,$Key[2])
$split=Split($wr,'|')
$wr=Join($split,' ')
$inst=Instr($wr,$Key[3])
if $inst exit 0 else exit 1 endif
else
$Index = $Index + 1
endif
loop
exit @error
endif

EndFunction

; Overall I'm not comfortable with the calls to array elements without
; some type of prior initialization as it could easily lead to a script abend.