Thursday 18 December 2014

C# code to system restore from code behind

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);
}

Note: Add reference of system.managment

No comments:

Post a Comment