Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to Rename a Registry Key

Keywords:    regkey rename

Question:

There's no registry key rename function in WinBatch that I can find. Is there one?

Answer:

In the WinBatch UDF library (in this same tech support database) is a registry cloning/renaming script.

Article ID: W14745


Or you could try the following:


//***************************************************************************
//** Rename registry key
//**
//** ****USE AT YOUR OWN RISK*****
//** This code will export a registry key to a  temporary .reg file 
//** Search and replace the registry key name strings in the .reg file 
//** Delete the original registry key
//** Import modified .REG file containing the renamed items
//** Delete the temporary .reg file
//***************************************************************************


 temp="c:\temp"
 Errormode(@OFF)
 RegHandle=@REGCLASSES 
 RegHive="HKEY_CLASSES_ROOT"
 RegKey="CLSID\{5b4dae26-b807-11d0-9815-00c04fd91972}"
 
 Search="CLSID\{5b4dae26-b807-11d0-9815-00c04fd91972}"
 Replace="CLSID\-{5b4dae26-b807-11d0-9815-00c04fd91972}"
 
 TempRegFile="%temp%\~regfile.reg"
 CaseSensitive=@FALSE
  
 RunWait("REGEDIT",'/e %TempRegFile% %RegHive%\%RegKey%') ;Exports current registry key
 gosub SEARCHREPLACE ;Replace Search with Replace, effectively renaming the key reference in the reg file
 RegDeleteKey(RegHandle,RegKey) ;Delete specified Registry Key
 RunWait("REGEDIT.EXE",'/s %TempRegFile%') ;Import modified .REG file containing the renamed items
 FileDelete(TempRegFile) ;Cleanup
 Exit
  
 :SEARCHREPLACE
  fs = FileSize( TempRegFile )
  binbuf = binaryalloc( fs*2 )
  Sourc = BinaryRead( binbuf, TempRegFile )
  num = BinaryReplace( binbuf, Search,Replace ,CaseSensitive)
  BinaryWrite( binbuf, TempRegFile)
  BinaryFree(binbuf)
  Return

Article ID:   W13737
Filename: Renaming Registry Keys.txt