How do I create a system restore point everytime my installer is run?

995 Views Asked by At

By default MSI creates a systrem restore point for installation and uninstallation. What do I have to do to create a system restore point everytime my installer is run, whether it is install, repair, remove, upgrade etc.?

2

There are 2 best solutions below

0
On

Well an upgrade is a fresh install of a new product, assuming you mean major upgrade so you shouldn't need to worry about that because the install will create one as it starts.

Uninstall is not often a problem assuming the user still has the install source and access to any updates because they can just reinstall the product.

Either way, you'd need to code it with the restore point API, starting with this:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa378727(v=vs.85).aspx

and I don't know if it works from a custom action. If it doesn't, then you'd need to wrap those operations in an executable that creates the restore point then runs the MSI.

If the user has turned off system restore then obviously none of this will work anyway.

0
On

Here is a function you can use

function CreateRestorePoint(sDescription: String): Boolean;
var
  ScriptControl:  Variant;
  oWMI:             Variant;
  ErrCode:          Integer;
begin
  try
    // Create the ScriptControl object.
    ScriptControl := CreateOleObject('ScriptControl');
    // Set the Language property (VBScript or JavaScript)
    ScriptControl.Language := 'VBScript';
    // Now create the WMI object we could not with straight Pascal code.
    oWMI := ScriptControl.Eval('GetObject("winmgmts:\\.\root\default:Systemrestore")');
    WizardForm.StatusLabel.Caption := 'Creating restore point...';
    // Create the restore point.
    ErrCode := oWMI.CreateRestorePoint(sDescription, 0, 100);
    // Return the error code, if any.  A value of zero indicates success.
    Result := (ErrCode = 0);
  except
    Result := false;
  end;
end;

Find more details here https://github.com/matlo/GIMX-build/blob/master/windows/inno.iss