I\'m looking for a way to create a system restore point with the current date and time by pressing a button. I\'ve tried searching the web for a simple way to do this but I
Late, but I improved the answer from M4N...
///
/// The type of event. For more information, see .
///
public enum EventType
{
///
/// A system change has begun. A subsequent nested call does not create a new restore
/// point.
///
/// Subsequent calls must use , not
/// .
///
///
BeginNestedSystemChange = 0x66,
///
/// A system change has begun.
///
BeginSystemChange = 0x64,
///
/// A system change has ended.
///
EndNestedSystemChange = 0x67,
///
/// A system change has ended.
///
EndSystemChange = 0x65
}
///
/// The type of restore point. For more information, see .
///
public enum RestorePointType
{
///
/// An application has been installed.
///
ApplicationInstall = 0x0,
///
/// An application has been uninstalled.
///
ApplicationUninstall = 0x1,
///
/// An application needs to delete the restore point it created. For example, an
/// application would use this flag when a user cancels an installation.
///
CancelledOperation = 0xd,
///
/// A device driver has been installed.
///
DeviceDriverInstall = 0xa,
///
/// An application has had features added or removed.
///
ModifySettings = 0xc
}
///
/// Creates a restore point on the local system.
///
///
/// The description to be displayed so the user can easily identify a restore point.
///
///
/// The type of event.
///
///
/// The type of restore point.
///
///
/// Access denied.
///
public static void CreateRestorePoint(string description, EventType eventType, RestorePointType restorePointType)
{
var mScope = new ManagementScope("\\\\localhost\\root\\default");
var mPath = new ManagementPath("SystemRestore");
var options = new ObjectGetOptions();
using (var mClass = new ManagementClass(mScope, mPath, options))
using (var parameters = mClass.GetMethodParameters("CreateRestorePoint"))
{
parameters["Description"] = description;
parameters["EventType"] = (int)eventType;
parameters["RestorePointType"] = (int)restorePointType;
mClass.InvokeMethod("CreateRestorePoint", parameters, null);
}
}
Example:
CreateRestorePoint("Example Restore Point", EventType.BeginSystemChange, RestorePointType.ModifySettings);