driver-updater

Windows app that checks Windows Update and hardware vendors for newer drivers and silently installs the driver.
git clone https://dittus.dev/git/driver-updater.git
Log | Files | Refs | README | Download

RestorePoint.cs (893B)


      1 using System.ComponentModel;
      2 
      3 namespace DriverUpdater;
      4 
      5 // Creates a System Restore point, so a bad driver can be rolled back from Windows recovery.
      6 static class RestorePoint
      7 {
      8     // Argument values for SystemRestore.CreateRestorePoint.
      9     const int DeviceDriverInstall = 10;
     10     const int BeginSystemChange = 100;
     11 
     12     // Returns null on success, or why it failed. Windows quietly skips the restore point if it made
     13     // one in the last 24 hours, and that still counts as success.
     14     public static string? Create(string description)
     15     {
     16         dynamic locator = Com.Create("WbemScripting.SWbemLocator");
     17         dynamic systemRestore = locator.ConnectServer(".", @"root\default").Get("SystemRestore");
     18         int code = systemRestore.CreateRestorePoint(description, DeviceDriverInstall, BeginSystemChange);
     19         return code == 0 ? null : new Win32Exception(code).Message;
     20     }
     21 }