Backup and restore extensions using VBScript

VB Script

 

There might be cases when multiple applications modify the same extension. With these simple scripts you can do a backup and restore of the registry in your MSI.

 

First, create a vbscript for backup:

 


quote = """"

Dim objShell
Set objShell = CreateObject("WScript.SHell")
WDir = objShell.ExpandEnvironmentStrings("%Windir%")
inst =WDir & "\installer\MyApp"

Set WshShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

if not fso.folderexists(inst) then
fso.CreateFolder(inst)
end if

if not fso.fileexists(inst & "backupcdx.reg") then
cmd = "reg export HKCR\.cdx" & " " & quote & inst & "\" & "backupcdx.reg" & quote
WshShell.Run cmd, 0, True
end if

 

This script creates a folder named “MyApp” in C:\Windows\Installer. By using the REG utility, we export the CDX extension registry from HKEY_CLASSES_ROOT to a backup reg file named “backupcdx”.

If you want to use this in your MSI, place the script as soon as possible (right after “InstallInitialize” sequence).

 

After we backed up the registry, we now have to restore it. To do so, we use the following script:

 


quote = """"
Set WshShell = CreateObject("WScript.Shell")
set fso = createObject("scripting.FileSystemObject")

Dim objShell
Set objShell = CreateObject("WScript.SHell")
WDir = objShell.ExpandEnvironmentStrings("%Windir%")
inst =WDir & "\installer\MyApp"
if fso.fileexists(inst & "backupcdx.reg") then
cmd = "reg import" & " " & quote & inst & "backupcdx.reg" & quote
WshShell.Run cmd, 0, True
fso.deletefile inst & "backupevt.reg"
end if

 

What this does is, we first search if the C:\Windows\Installer\MyApp\backupcdx.reg is present, and if it is, we use the REG utility to import the previously exported registry. This script should be placed at the end of the execution sequence (before the “InstallFinalize” sequence).

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

nineteen − thirteen =