; Here is a subroutine that can copy move or rename
; a registry key. The whole thing is based on the
; "enumkeys.kix" (thanks Shawn !) script file that comes
; with the kixtart distribution.
;
; In order this subroutine to work you have first to
; define The $source_key, $destination_key, and $action
; $action can be : "move", "rename", or "copy"
;
; This script comes in two parts. The main script
; "main.kix" is actually your script and can have
; any name. Be carefull to place the "tree.kix" at the
; same directory as "main.kix"
$source_key = "HKEY_LOCAL_MACHINE\SYSTEM\TEST"
$destination_key = "HKEY_LOCAL_MACHINE\SOFTWARE\TEST2"
$action = "move"
gosub manage_key
;----------------------------------------------------------
; Subroutines
;----------------------------------------------------------
goto end
:manage_key
gosub security_check if $secheck=1 return endif
gosub correct_key_names $zz=len($source_key)
call tree.kix
if $action <> "copy"
$nul=deltree("$source_key")
endif
return
;-----------------------
:correct_key_names
if substr($source_key,len($source_key),1)="\"
$source_key=substr($source_key,1,len($source_key)-1)
endif
if substr($destination_key,len($destination_key),1)="\"
$destination_key=substr($destination_key,1,len($destination_key)-1)
endif
return
;-----------------------
:security_check
$secheck=0
select
case ( ( $action<>"move" ) and ( $action<>"copy" ) and ( $action<>"rename" ) )
$secheck=1 'The variable $$action is not defined right. Please use' ?
'for this variable one of the following values :' ?
'"move" , "rename" , or "copy"' ?
case exist( @scriptdir + "\" + "tree.kix" )<>1
$secheck=1 'The library file "tree.kix" could not be found' ?
'at current directory' ?
case $source_key=""
$secheck=1 'You have not define the $$source_key' ?
case $destination_key=""
$secheck=1 'You have not define the $$destination_key' ?
case existkey("$source_key")<>0
$secheck=1 'The source key does not exist' ?
case existkey("$destination_key")=0
$secheck=1 'The destiantion key already exist. The destination' ?
'key must be absent in order this script to work.' ?
return
case addkey("$destination_key")<>0
$secheck=1 'Can not create the destination key. Probably you' ?
'do not have the required permissions' ?
endselect
$nul=delkey("$destination_key")
:quit_with_error2
return
;-----------------------
:end