每次运行安装程序时如何创建系统还原点?

时间:2015-01-23 09:35:27

标签: wix windows-installer system-restore

默认情况下,MSI会为安装和卸载创建systrem还原点。每次运行安装程序时,无论是安装,修复,删除,升级等,都需要做什么才能创建系统还原点?

2 个答案:

答案 0 :(得分:0)

升级是新产品的全新安装,假设您的意思是重大升级,因此您不必担心这一点,因为安装会在启动时创建一个。

如果用户仍然拥有安装源并可以访问任何更新,则卸载通常不会成为问题,因为他们只能重新安装产品。

无论哪种方式,您都需要使用还原点API对其进行编码,从此开始:

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

我不知道它是否适用于自定义操作。如果它没有,那么您需要将这些操作包装在创建还原点的可执行文件中,然后运行MSI。

如果用户关闭了系统还原,那么显然这一切都无法正常工作。

答案 1 :(得分:0)

这是一个你可以使用的功能

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;

在此处查找更多详细信息https://github.com/matlo/GIMX-build/blob/master/windows/inno.iss