I have created a new installer using NSIS. When installing this new version of the installer, if the previous version of the installer is present I am removing that installer and installing the new installer.
But before uninstalling the previous installer i wanted to store (export) the registry entries of the previous installer and then import (restore) the .reg file values with the new installer.
My Previous installer registry path is: \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\EMR\3.01.00
My Current installer registry path is: \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\EMR\4.01.00
I am exporting (storing the registry values) like as shown below using NSIS:
${registry::SaveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\EMR" "C:\Code\Changes\regfile.reg" "/G=1 /D=2" $R0
${registry::Unload}
MessageBox MB_OK "PPC-registry::SaveKey$\n$\n\
Errorlevel: [$R0]"
**Importing the registry values like as shown below:**
IfFileExists "C:\Code\Changes\regfile.reg" file_found file_not_found
file_found:
${registry::RestoreKey} "C:\Code\Changes\regfile.reg" $R0
MessageBox MB_OK "PPC-registry::RestoreKey$\n$\n\
Errorlevel: [$R0]"
goto end_of_test file_not_found: MessageBox MB_ICONEXCLAMATION|MB_OK "File does not exist" end_of_test:
But with the above code snippet when restoring the .reg file, in the registry it is showing EMR\3.01.00 AND EMR\4.01.00. And also after the import, the sequence of the registry key values are changing.
Please help me how to restore the old registry values but show only EMR\4.01.00.
Method 2:
And also I am using the VB script to export and import the registry values like as shown below:
Exporting the Registry:
**Importing the Registry:** <Property Id="IMPORT_REG">
<![CDATA[
function importReg
Dim regfile, userDir, oShell
Set oShell = CreateObject("WScript.Shell")
userDir = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
regfile = userDir & "\tempkeyPCPE.reg"
Return = oShell.Run("regedit /s """ & regfile & """",0,True)
userDir = ""
end function
]]>
</Property>
Then using the WIX Installer, I am calling EXPORT_REG and IMPORT_REG like as shown below:
<CustomAction Id="ExportRegistry"
VBScriptCall="exportReg"
Property="EXPORT_REG" Return="ignore"/>
<CustomAction Id="ImportRegistry"
VBScriptCall="importReg"
Property="IMPORT_REG"
Execute="deferred"
Impersonate="no" Return="ignore"/>
Please help me how to export and import the VB script calls using NSIS?
You should not use ${registry::RestoreKey}
, use ${registry::MoveKey}
to move a key.
If you only support Windows 2000 and later you can also call the API directly:
!include LogicLib.nsh
!include WinCore.nsh
Section
WriteRegStr HKCU "Software\Test\v1" "Hello" "World"
WriteRegDWORD HKCU "Software\Test\v1\Number" "" 42
!define /IfNDef MAXIMUM_ALLOWED 0x02000000
!define /IfNDef KEY_READ 0x20019
System::Call 'ADVAPI32::RegOpenKeyEx(p ${HKEY_CURRENT_USER}, t "Software\Test\v1", i 0, i ${KEY_READ}, *p0r1)i.r0'
${If} $0 = 0
System::Call 'ADVAPI32::RegCreateKeyEx(p ${HKEY_CURRENT_USER}, t "Software\Test\v2", i 0, p 0, i 0, i ${MAXIMUM_ALLOWED}, p 0, *p0r2, *i)i.r0'
${If} $0 = 0
System::Call 'ADVAPI32::RegCopyTree(pr1, p0, pr2)i.r0'
${If} $0 == "error"
System::Call 'SHLWAPI::SHCopyKey(pr1, p0, pr2, i0)i.r0'
${EndIf}
${If} $0 = 0
DeleteRegKey HKEY_CURRENT_USER "Software\Test\v1" ; Delete the old key (optional)
${EndIf}
${EndIf}
${EndIf}
SectionEnd