Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#2

AW: Windows 10 und System Restore

  Alt 18. Mär 2017, 09:23
Die 3 Methoden funktionieren bei WIN8.1 nicht, deshalb kann ich es mir ersparen, sie bei WIN10 zu testen.

Folgende Codes funktionieren bei mir:
1. CreateRestorePoint
2. RestorePoints auslesen

Delphi-Quellcode:
//You can use the CreateRestorePoint from the SystemRestore WMI class

program CreateRestorePoint;

{$APPTYPE CONSOLE}

uses
// SysUtils, ActiveX, ComObj;
  System.SysUtils, Winapi.ActiveX, System.Win.ComObj;

procedure CreateRestorePoint2(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
      CreateRestorePoint2('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.
Delphi-Quellcode:
program   RestorePoint;
//Author Rodrigo Ruz 14/04/2010.
{$APPTYPE CONSOLE}
 
uses
// SysUtils,ActiveX,ComObj,Variants;
  System.SysUtils,Winapi.ActiveX,System.Win.ComObj,System.Variants;

function RestorePointTypeToStr(RestorePointType:Integer):string;
begin
     case RestorePointType of
      0 : Result:='APPLICATION_INSTALL';
      1 : Result:='APPLICATION_UNINSTALL';
      13 : Result:='CANCELLED_OPERATION';
      10 : Result:='DEVICE_DRIVER_INSTALL';
      12 : Result:='MODIFY_SETTINGS'
      else
      Result:='Unknow';
     end;
end;
 
function EventTypeToStr(EventType:integer) : string;
begin
     case EventType of
      102 : Result:='BEGIN_NESTED_SYSTEM_CHANGE';
      100 : Result:='BEGIN_SYSTEM_CHANGE';
      103 : Result:='END_NESTED_SYSTEM_CHANGE';
      101 : Result:='END_SYSTEM_CHANGE'
      else
      Result:='Unknow';
     end;
end;
 
function WMITimeToStr(WMITime:string) : string; //convert to dd/mm/yyyy hh:mm:ss
begin
    //20020710113047.000000420-000 example source http://technet.microsoft.com/en-us/library/ee156576.aspx
    result:=Format('%s/%s/%s %s:%s:%s',[copy(WMITime,7,2),copy(WMITime,5,2),copy(WMITime,1,4),copy(WMITime,9,2),copy(WMITime,11,2),copy(WMITime,13,2)]);
end;
 
procedure GetRestorePoints;
var
  oSWbemLocator : OLEVariant;
  objWMIService : OLEVariant;
  colItems : OLEVariant;
  colItem : OLEVariant;
  oEnum : IEnumvariant;
  iValue : LongWord;
begin
  oSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  objWMIService := oSWbemLocator.ConnectServer('localhost', 'root\default', '', '');
  colItems := objWMIService.ExecQuery('SELECT * FROM SystemRestore','WQL',0);
  oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
  while oEnum.Next(1, colItem, iValue) = 0 do
  begin
      WriteLn(Format('%s %-15s',['Description',colItem.Description]));
      WriteLn(Format('%s %-15s',['RestorePointType',RestorePointTypeToStr(colItem.RestorePointType)]));
      WriteLn(Format('%s %-15s',['EventType',EventTypeToStr(colItem.EventType)]));
      WriteLn(Format('%s %-15s',['SequenceNumber',colItem.SequenceNumber]));
      WriteLn(Format('%s %-15s',['CreationTime',WMITimeToStr(colItem.CreationTime)]));
      Writeln;
      colItem:=Unassigned;
  end;
end;
 
begin
 try
    CoInitialize(nil);
    try
      GetRestorePoints;
    finally
      CoUninitialize;
    end;
 except
    on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
  end;
  Readln;
end.
  Mit Zitat antworten Zitat