创建系统还原点 - 有什么想法吗?

Nic*_*ick 5 system-restore

以编程方式创建系统还原点是“禁忌”吗?我会在执行软件更新之前执行此操作。如果有更好的方法仅使用我的软件的文件和数据创建还原点,请告诉我。

我想要一种方法,如果更新过程中一切都崩溃了(关闭/终止更新应用程序、断电、用户拔掉插头等),我可以让用户回到已知的工作状态

    private void CreateRestorePoint(string description)
    {
        ManagementScope oScope = new ManagementScope("\\\\localhost\\root\\default");
        ManagementPath oPath = new ManagementPath("SystemRestore");
        ObjectGetOptions oGetOp = new ObjectGetOptions();
        ManagementClass oProcess = new ManagementClass(oScope, oPath, oGetOp);

        ManagementBaseObject oInParams = oProcess.GetMethodParameters("CreateRestorePoint");
        oInParams["Description"] = description;
        oInParams["RestorePointType"] = 12; // MODIFY_SETTINGS
        oInParams["EventType"] = 100;

        ManagementBaseObject oOutParams = oProcess.InvokeMethod("CreateRestorePoint", oInParams, null); 
    }
Run Code Online (Sandbox Code Playgroud)

DrP*_*zza 5

以编程方式创建系统还原点是“禁忌”吗?

不,这就是 API 存在的原因;这样您就可以对系统进行伪原子更新。