I have already solved this problem, use the following script. The script in help of AI is wrong!
' -----------------------------------------------------------------------------
' @info BackupKey script
' -----------------------------------------------------------------------------
'Function BackupKey
On Error Resume Next
Dim inputArray, token
'Dim sourceKeyList, sourceArray, sourceKey
'set the registry hive used in the custom action
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_RESOURCE_LIST = 8
Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Const REG_RESOURCE_REQUIREMENTS_LIST = 10
'create an object which handles the registry operations
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
'set the main registry keys
targetKey = ""
sourceKeyList = ""
custActData = Session.Property("CustomActionData")
If Len(custActData) = 0 Then
ExitFunction
End If
WriteToLog("[BackupKey]: CustomActionData=" & custActData)
' Target<>SourceList
inputArray = Split(custActData, "<>", -1)
i = 0
For Each token In inputArray
If i = 0 Then
targetKey = Trim(token)
ElseIf i = 1 Then
sourceKeyList = Trim(token)
End If
i = i + 1
Next
If Len(targetKey) = 0 Then
ExitFunction
End If
WriteToLog("[BackupKey]: Target Key: " & targetKey)
If Len(sourceKeyList) = 0 Then
ExitFunction
End If
WriteToLog("[BackupKey]: Source Key list: " & sourceKeyList)
MainTargetKey = TrailingBackslash(targetKey)
Maintarget = Right(targetKey, Len(targetKey) - InStr(targetKey,"\"))
If MainTargetKey = "" Then
ExitFunction
ElseIf Len(Maintarget) = 0 Then
ExitFunction
End If
'create the backup key
objReg.CreateKey MainTargetKey, Maintarget
' This array contains the full source Keys
sourceArray = Split(sourceKeyList, "|", -1)
For Each sourceKey In sourceArray
If Len(sourceKey) <> 0 Then
MainSourceKey = TrailingBackslash(sourceKey)
source = Right(sourceKey, Len(sourceKey) - InStr(sourceKey,"\"))
target = Maintarget & "\" & Right(sourceKey, Len(sourceKey) - InStrRev(sourceKey,"\"))
WriteToLog("[BackupKey]: Main Source key: " & Chr(34) & MainSourceKey & Chr(34))
WriteToLog("[BackupKey]: Source key: " & Chr(34) & source & Chr(34))
WriteToLog("[BackupKey]: Main Target key: " & Chr(34) & MainTargetKey & Chr(34))
WriteToLog("[BackupKey]: Target key: " & Chr(34) & target & Chr(34))
'create the backup key
objReg.CreateKey MainTargetKey, target
'call the function which copies everything from the target key
CopyKey MainSourceKey, source, MainTargetKey, target
End If
Next
ExitFunction
'Exit Function
' -----------------------------------------------------------------------------
'the copy function
' -----------------------------------------------------------------------------
Sub CopyKey(MainSourceKey, source, MainTargetKey, target)
'enumerate all subkeys of the main key
objReg.EnumKey MainSourceKey, source, SubKeysList
'for each subkey call the copy function
If IsArray(SubKeysList) Then
For Each SubKey In SubKeysList
If Len(SubKey) <> 0 Then
'create the subkey in the backup key before calling the copy function for it
objReg.CreateKey MainTargetKey, target & "\" & SubKey
End If
CopyKey MainSourceKey, source & "\" & SubKey, MainTargetKey, target & "\" & SubKey
Next
End If
'enumerate the values in the current key
objReg.EnumValues MainSourceKey, source, ValueList, ValueTypes
'copy each value to the corresponding backup key
If IsArray(ValueList) Then
For i = 0 To UBound(ValueList)
If Len(ValueList(i)) <> 0 Then
Select Case ValueTypes(i)
Case REG_SZ
objReg.GetStringValue MainSourceKey, source, ValueList(i), Value
objReg.SetStringValue MainTargetKey, target, ValueList(i), Value
Case REG_MULTI_SZ
objReg.GetMultiStringValue MainSourceKey, source, ValueList(i), Value
objReg.SetMultiStringValue MainTargetKey, target, ValueList(i), Value
Case REG_EXPAND_SZ
objReg.GetExpandedStringValue MainSourceKey, source, ValueList(i), Value
objReg.SetExpandedStringValue MainTargetKey, target, ValueList(i), Value
Case REG_DWORD
objReg.GetDWORDValue MainSourceKey, source, ValueList(i), Value
objReg.SetDWORDValue MainTargetKey, target, ValueList(i), Value
'objReg.GetQuadWordValue MainSourceKey, source, ValueList(i), Value
'objReg.SetQuadWordValue MainTargetKey, target, ValueList(i), Value
Case REG_BINARY
objReg.GetBinaryValue MainSourceKey, source, ValueList(i), Value
objReg.SetBinaryValue MainTargetKey, target, ValueList(i),Value
End Select
End If
Next
End If
End Sub
' -----------------------------------------------------------------------------
' @info Removes the trailing backslash \ (if there is one)
' -----------------------------------------------------------------------------
Function TrailingBackslash(KeyPath)
TrailingBackslash = ""
If Left(KeyPath, InStr(KeyPath,"\")-1) = "HKCR" Then
TrailingBackslash = HKEY_CLASSES_ROOT
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKEY_CLASSES_ROOT" Then
TrailingBackslash = HKEY_CLASSES_ROOT
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKCU" Then
TrailingBackslash = HKEY_CURRENT_USER
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKEY_CURRENT_USER" Then
TrailingBackslash = HKEY_CURRENT_USER
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKLM" Then
TrailingBackslash = HKEY_LOCAL_MACHINE
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKEY_LOCAL_MACHINE" Then
TrailingBackslash = HKEY_LOCAL_MACHINE
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKUR" Then
TrailingBackslash = HKEY_USERS
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKEY_USERS" Then
TrailingBackslash = HKEY_USERS
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKCC" Then
TrailingBackslash = HKEY_CURRENT_CONFIG
ElseIf Left(KeyPath, InStr(KeyPath,"\")-1) = "HKEY_CURRENT_CONFIG" Then
TrailingBackslash = HKEY_CURRENT_CONFIG
End If
End Function
' -----------------------------------------------------------------------------
' @info Writes the specified string in the Windows Installer log file
' -----------------------------------------------------------------------------
Function WriteToLog(msg)
Const msiMessageTypeInfo = &H04000000
Set record = Session.Installer.CreateRecord(1)
record.StringData(0) = "[1]"
record.StringData(1) = CStr(msg)
Session.Message msiMessageTypeInfo, record
End Function
' -----------------------------------------------------------------------------
' @info to exit run of script
' -----------------------------------------------------------------------------
Sub ExitFunction()
End Sub