Create a Restore Point In Windows 10

Stef Merlijn
Stef Merlijn used Ask the Experts™
on
Hi,

How can I create a system restorepoint in Windows 7, 8 and 10 from within Delphi XE2 Professsional?

I already found some resources, but have no idea if these are still valid or if there is an easier way to set things up.

Some old sourcecode based on Windows XP:
http://www.swissdelphicenter.ch/en/showcode.php?id=1650
Microsoft Script Control ActiveX control:
https://www.microsoft.com/en-us/download/details.aspx?id=1949
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software architect
Top Expert 2012
Commented:
Upon this example which use WMI to access SystemRestore - I make call to create new restore point:

procedure GetRestorePoints(list: TStringList);
const
  wbemFlagForwardOnly = $00000020;
var
  oSWbemLocator : OLEVariant;
  objWMIService : OLEVariant;
  colItems      : OLEVariant;
  colItem       : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin
  list.Clear;

  oSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  objWMIService := oSWbemLocator.ConnectServer('localhost', 'root\default', '', ''); 
  colItems := objWMIService.ExecQuery('SELECT * FROM SystemRestore','WQL', wbemFlagForwardOnly);
  oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
  while oEnum.Next(1, colItem, iValue) = 0 do
  begin
    list.Add(Format('%s %-15s',['Description',colItem.Description]));
    list.Add(Format('%s %-15s',['RestorePointType',RestorePointTypeToStr(colItem.RestorePointType)]));
    list.Add(Format('%s %-15s',['EventType',EventTypeToStr(colItem.EventType)]));
    list.Add(Format('%s %-15s',['SequenceNumber',colItem.SequenceNumber]));
    list.Add(Format('%s %-15s',['CreationTime',WMITimeToStr(colItem.CreationTime)]));
    list.Add('');
    colItem:=Unassigned;
  end;
end;

procedure SetRestorePoint(const Description : string);
const
  BEGIN_SYSTEM_CHANGE = 100;
  APPLICATION_INSTALL = 0;
var
  oSWbemLocator : OLEVariant;
  objWMIService : OLEVariant;
  sr: OLEVariant;
begin
  oSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  objWMIService := oSWbemLocator.ConnectServer('localhost', 'root\default', '', '');
  sr:= objWMIService.Get('SystemRestore');
  sr.CreateRestorePoint(Description, APPLICATION_INSTALL, BEGIN_SYSTEM_CHANGE);
end;
//http://www.delphifeeds.com/go/s/67322
procedure TForm1.Button2Click(Sender: TObject);
begin
  try
    CoInitialize(nil);
    try
      GetRestorePoints(TStringList(Memo1.Lines));
    finally
      CoUninitialize;
    end;
  except
    on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  try
    CoInitialize(nil);
    try
      SetRestorePoint('My restore point');
    finally
      CoUninitialize;
    end;
  except
    on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
  end;
end;

Open in new window


Missing function - take it from link above...
Stef MerlijnDeveloper

Author

Commented:
This works perfectly. Thank you very much.
Stef MerlijnDeveloper

Author

Commented:
Some additional info that might be useful also:
RestorePointType [in] The type of restore point. This member can be one of the following values.
  APPLICATION_INSTALL        =   0;  An application has been installed.
  APPLICATION_UNINSTALL      =   1;  An application has been uninstalled.
  DEVICE_DRIVER_INSTALL      =  10;  A device driver has been installed.
  MODIFY_SETTINGS            =  12;  An application has had features added or removed.
  CANCELLED_OPERATION        =  13;  An application needs to delete the restore point it created. For example, an application would use this flag when a user cancels an installation.

EventType [in] The type of event. This member can be one of the following values.
  BEGIN_NESTED_SYSTEM_CHANGE = 102;  A system change has begun. A subsequent nested call does not create a new restore point. Subsequent calls must use END_NESTED_SYSTEM_CHANGE, not END_SYSTEM_CHANGE.
  BEGIN_SYSTEM_CHANGE        = 100;  A system change has begun. A subsequent call must use END_SYSTEM_CHANGE, not END_NESTED_SYSTEM_CHANGE.
  END_NESTED_SYSTEM_CHANGE   = 103;  A system change has ended.
  END_SYSTEM_CHANGE          = 101;  A system change has ended.

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial