Copy Reg Keys from HKCU to HKLM

email me

I wrote this script to copy registry keys from a current user registry hive to the local machine registry hive. I was using this with desktop management software.

ON ERROR RESUME NEXT

CONST HKEY_CURRENT_USER   = &H80000001  
CONST HKEY_LOCAL_MACHINE  = &H80000002
CONST REG_SZ = 1
CONST REG_DWORD = 4
  
'USE LOCAL COMPUTER NAME
strComputer = "."
SET StdOut = WScript.StdOut  
  
'CONNECT TO REGISTRY
SET objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")  
  
'REG KEY IMPORT FROM HKCU TO HKLM
strKeySource = "SOFTWARE\MYINFO"''''FROM THE CURRENT USER HIVE
strKeyDestination = "SOFTWARE\MYINFO"''''TO THE LOCAL MACHINE HIVE
  
'CREATE THE DESTINATION KEY  
objRegistry.CreateKey HKEY_LOCAL_MACHINE,strKeyDestination
  
'ENUMERATE KEYS FROM CURRENT USER AND THEN APPLY VALUES TO HKLM
objRegistry.EnumValues HKEY_CURRENT_USER, strKeySource, arrValueNames, arrValueTypes
FOR i = LBound(arrValueNames) To UBound(arrValueNames)  
         objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyDestination,arrValueNames(i),value
	 objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyDestination,arrValueNames(i),value
NEXT

WScript.Quit(0)