Skip to content

Instantly share code, notes, and snippets.

@kek-Sec
Created July 1, 2017 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kek-Sec/23604e7b3af41592a934dc41f836c17a to your computer and use it in GitHub Desktop.
Save kek-Sec/23604e7b3af41592a934dc41f836c17a to your computer and use it in GitHub Desktop.
C# Find and Delete system restore points
using System.Management;
using System.Runtime.InteropServices;
[DllImport("Srclient.dll")]
public static extern int DeleteRestorePoint(int index);
private void SearchAndDestroySystemRestore()
{
//Find sequence numbers of system restore points
System.Management.ManagementClass objClass = new System.Management.ManagementClass("\\\\.\\root\\default", "systemrestore", new System.Management.ObjectGetOptions());
System.Management.ManagementObjectCollection objCol = objClass.GetInstances();
String[] sequencenums = new String[100];
int c = 0;
foreach (System.Management.ManagementObject objItem in objCol)
{
sequencenums[c] = (((uint)objItem["sequencenumber"]).ToString());
c++;
}
//Delete them
while (c >= 0)
{
DeleteRestorePoint(Convert.ToInt32(sequencenums[c]));
c--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment