#52606 - 2000-12-07 07:28 PM
moving renaming and coping registry keys
|
Anonymous
Anonymous
Unregistered
|
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).]
|
Top
|
|
|
|
#52608 - 2000-12-12 05:35 PM
Re: moving renaming and coping registry keys
|
Daa
Fresh Scripter
Registered: 2000-09-06
Posts: 14
Loc: Delft, Netherlands
|
I've done some testing with it and I made 1 minor change to Tree.kix, because I could not get it to do what I thought it should do.I've added the following line just before the exit 0 command:
code:
$key=""
This clears the variable at the end, which is necessary when you want to want to change multiple registry keys within one script.------------------ Grtx, Dennis. [This message has been edited by TNOTPD (edited 12 December 2000).]
_________________________
Grtx, Dennis.
|
Top
|
|
|
|
#52609 - 2005-11-03 08:34 PM
Re: moving renaming and coping registry keys
|
thrain78
Fresh Scripter
Registered: 2005-10-28
Posts: 7
|
This post was very helpful for migration of user profiles in my environment.
I wanted to drop a question into this old post, and see.
Would it be possible to convert this thing into a fnRegKeyChange($sourcekey,$destkey,$action)
then we could call it just by passing variables?
I am so not a coder, but am going to attempt to this coding. any thoughts would be wonderful.
|
Top
|
|
|
|
#52610 - 2005-11-03 09:39 PM
Re: moving renaming and coping registry keys
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Please DO NOT post to or drag up Ancient/Old posts. Post your own topic and reference this one if needed.
Please take a look here for a possible UDF.
RegUpdate() - Local/Remote registry datatype update
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 700 anonymous users online.
|
|
|