How to remove Windows restore points in C #?

I am looking for a way to remove Windows recovery points using C #, possibly by calling WMI.

Any piece of code will be very helpful.

+3
source share
2 answers

Touching on what Morten said, you can use this API. As far as I can tell, WMI does not provide a method to delete a recovery point. SRRemoveRestorePoint can delete a restore point if you have a serial number. You can get this through WMI. Here is my code to remove the recovery point.

[DllImport("Srclient.dll")]
public static extern int SRRemoveRestorePoint(int index);

private void button1_Click(object sender, EventArgs e)
{
    int SeqNum = 335;
    int intReturn = SRRemoveRestorePoint(SeqNum);
}

335, , . , 1 . , , .

, Microsoft #, . System.Management . .

    private void EnumRestorePoints()
    {
        System.Management.ManagementClass objClass = new System.Management.ManagementClass("\\\\.\\root\\default", "systemrestore", new System.Management.ObjectGetOptions());
        System.Management.ManagementObjectCollection objCol = objClass.GetInstances();

        StringBuilder Results = new StringBuilder();
        foreach (System.Management.ManagementObject objItem in objCol)
        {
            Results.AppendLine((string)objItem["description"] + Convert.ToChar(9) + ((uint)objItem["sequencenumber"]).ToString());
        }

        MessageBox.Show(Results.ToString());
    }

(, Vista), . Admin, , .

+9

WMI, . , , , -. , , Win32/COM SRRemoveRestorePoint. , .

VBScript, .

0

Source: https://habr.com/ru/post/1702802/


All Articles