2

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
Community
  • 1
  • 1

1 Answers1

4

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.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Thanks, sadly, does not work. Using an elevated Command Prompt the console program returns instantly with "0 Press Enter to exit" and on checking the Restore Point list there is no new entry. I will create an answer here and show the code changes and results after I added writelns in to see if that can help anyone diagnose the problem. Thanks again for the starting help. – user3046760 Dec 08 '13 at 17:43
  • If the `CreateRestorePoint` method returns `0`, means which the restore point was created. So how are you listing the existing restore points? – RRUZ Dec 08 '13 at 18:27
  • Thanks for looking at it but it returns that Zero instantly so there is no actual restore point created as it takes about 6-seconds normally to create one. To see the list I use Control Panel -> Recovery -> Open System Restore -> Next -> Show More Restore Points. The list is displayed for the points I have created manually using Control Panel -> Recovery -> Configure System restore -> Create. – user3046760 Dec 09 '13 at 21:57
  • That is weird, can you run this command `Get-ComputerRestorePoint` from a elevated PowerShell instance? – RRUZ Dec 09 '13 at 23:37
  • Got an error 'Windows PowerShell Copyright (C) 2012 Microsoft Corporation. All rights reserved. PS C:\Users\Admin> Get-ComputerRestorePoint Get-ComputerRestorePoint : Access denied At line:1 char:1+ Get-ComputerRestorePoint + CategoryInfo : InvalidOperation: (:) [Get-ComputerRestorePoint], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetComputerRestorePointCommand ' – user3046760 Dec 10 '13 at 17:55
  • You must run PowerShell as Admin. – RRUZ Dec 10 '13 at 18:27