Create a Restore Point In Windows 10

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
Stef MerlijnDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
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...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stef MerlijnDeveloperAuthor Commented:
This works perfectly. Thank you very much.
Stef MerlijnDeveloperAuthor 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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.