How to set System Restore points in Win8

684 views Asked by At

Using D5, I'd like to have an application that creates a System Restore point with a description. I have found several freebies online but they do not work with Win8, but they do work with Win7.

I found this question, which has me half way to accomplishing what I need to do as it does work with Win8 when compiled and run "As Administrator."

I also found a page on MSDN that describes a method using WScript and Task Scheduler which takes about the right amount of time to create a point, then reports "created," but on checking the System Restore Point list there is nothing there in Win8. But, again that process does work in Win7 and correctly shows the point created.

I also found this in VB and C which are both beyond my abilities to convert to Delphi version 5.

Can anyone please point me at the some code that will allow me to complete this project? It's for my own use so it can be a little rough and ready as long as it works with Win8.

OK as I commented below, here is what I did to help try and diagnose the issue.

program Project2;
{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj;

procedure  CreateRestorePoint(const Description : string);
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  BEGIN_SYSTEM_CHANGE = 100;
  APPLICATION_INSTALL = 0;
var
  FSWbemLocator   : OLEVariant;
  FWMIService     : OLEVariant;
  FWbemObjectSet  : OLEVariant;
begin
  WriteLn('2a');
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  WriteLn('2b');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\DEFAULT', WbemUser, WbemPassword);
  WriteLn('2c');
  FWbemObjectSet:= FWMIService.Get('SystemRestore');
  WriteLn('2d');
  Writeln(FWbemObjectSet.CreateRestorePoint(Description, APPLICATION_INSTALL, BEGIN_SYSTEM_CHANGE));  //
  WriteLn('2e');
end;


begin
 try
    WriteLn('1');
    CoInitialize(nil);
    try
      WriteLn('2');
      CreateRestorePoint('Sample restore point');
    finally
      WriteLn('3');
      CoUninitialize;
    end;
 except
    on E:EOleException do
    begin
      WriteLn('4');
      Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    end;
    on E:Exception do
    begin
      WriteLn('5');
      Writeln(E.Classname, ':', E.Message);
    end;
  end;
 Writeln('Press Enter again to exit');
 Readln;
end.

And here is the output from that...

1
2
2a
2b
2c
2d
0
2e
3
Press Enter again to exit
1

There are 1 answers

6
RRUZ On

You can use the CreateRestorePoint from the SystemRestore WMI class

Try this sample

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj;

procedure  CreateRestorePoint(const Description : string);
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  BEGIN_SYSTEM_CHANGE = 100;
  APPLICATION_INSTALL = 0;
var
  FSWbemLocator   : OLEVariant;
  FWMIService     : OLEVariant;
  FWbemObjectSet  : OLEVariant;
begin
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\DEFAULT', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.Get('SystemRestore');
  Writeln(FWbemObjectSet.CreateRestorePoint(Description, APPLICATION_INSTALL, BEGIN_SYSTEM_CHANGE));  //
end;


begin
 try
    CoInitialize(nil);
    try
      CreateRestorePoint('Sample restore point');
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
  end;
 Writeln('Press Enter to exit');
 Readln;
end.

Note: This code requires elevation.