Here is a subroutine that you can add to your scripts for renaming moving and copying registry keys. I took the basic idea (I think all...) from the enumkeys.kix that comes with kixtart distrubution. You have to place the file tree.kix to the same directory where your login script is. The script come in two parts. The login script with the subroutine and the "tree.kix". Both can be downloaded from :
http://users.otenet.gr/~novastar/scripts/mng_key.zip


The main login script :

code:

; 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


The "tree.kix"

code:


; Do not edit this file !!! It is used by the main script
; in order to extract the right registry values and keys.
; Place it to the same directory where your main script is
; and do not change its name. Basically it is the same
; script that comes with kixtart distribution "enumkeys.kix"
; changed a little bit in order to perform what I wanna to do.


break on
DIM $k, $SaveKey

if $key="" $key=$source_key endif

$k=0
$SubKey = enumkey($key,$k)

while @error=0

$SaveKey=$key
$key =$key + "\" + $subkey

$work_key=$destination_key+substr($key,$zz+1,len($key)-$zz)
$nul=addkey("$work_key")

CALL tree.kix

$key = $SaveKey
if @ERROR = 0
; try for next subkey
$k=$k+1
$subkey = enumkey( $key , $k )
endif
loop

; Lastly, enumerate all values of current key
$k = 0
$Value = EnumValue( $key , $k )
while @error=0

$work_key=$destination_key+substr($key,$zz+1,len($key)-$zz)
$nul=writevalue("$work_key","$Value",readvalue("$key","$Value"),readtype("$key","$Value"))

$k =$k+1
$Value = EnumValue( $key , $k )
loop
exit 0




[This message has been edited by novastar (edited 07 December 2000).]