Listing punktów przywracania

0

Kombinuję z wylistowaniem wszystkich nazw punktów przywracania systemu.

Mam już kasowanie i tworzenie punktów, brakuje mi tylko odczytać listę tych punktów.

Tworzenie punktu:

const
 BEGIN_SYSTEM_CHANGE = 100;
 END_SYSTEM_CHANGE  = 101;
 APPLICATION_INSTALL =  0;
 CANCELLED_OPERATION = 13;
 MAX_DESC = 64;
 MIN_EVENT = 100;

type
PRESTOREPTINFOA = ^_RESTOREPTINFOA;
_RESTOREPTINFOA = packed record
    dwEventType: DWORD;  // Type of Event - Begin or End
    dwRestorePtType: DWORD;  // Type of Restore Point - App install/uninstall
    llSequenceNumber: INT64;  // Sequence Number - 0 for begin
    szDescription: array [0..MAX_DESC] of CHAR; // Description - Name of Application / Operation
end;
RESTOREPOINTINFO = _RESTOREPTINFOA;
PRESTOREPOINTINFOA = ^_RESTOREPTINFOA;

PSMGRSTATUS = ^_SMGRSTATUS;
_SMGRSTATUS = packed record
    nStatus: DWORD; // Status returned by State Manager Process
    llSequenceNumber: INT64;  // Sequence Number for the restore point
end;
STATEMGRSTATUS =  _SMGRSTATUS;
PSTATEMGRSTATUS =  ^_SMGRSTATUS;

function SRSetRestorePointA(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus: PSTATEMGRSTATUS): Bool;
  stdcall; external 'SrClient.dll' Name 'SRSetRestorePointA';

//wywołanie
const
 CR = #13#10;
var
  RestorePtSpec: RESTOREPOINTINFO;
  SMgrStatus: STATEMGRSTATUS;
begin
  RestorePtSpec.dwEventType := BEGIN_SYSTEM_CHANGE;
  RestorePtSpec.dwRestorePtType := APPLICATION_INSTALL;
  RestorePtSpec.llSequenceNumber := 0;
  RestorePtSpec.szDescription := 'SAMPLE RESTORE POINT'; // nazwa punktu

  if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
    ShowMessage('Restore point set. Restore point data:' + CR+
      'Sequence Number: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR+
      'Status: ' + Format('%u', [SMgrStatus.nStatus]))
    else ShowMessage('Couldn''t set restore point.');
end;

Kasowanie punktu:

const
 BEGIN_SYSTEM_CHANGE = 100;
 END_SYSTEM_CHANGE  = 101;
 APPLICATION_INSTALL =  0;
 CANCELLED_OPERATION = 13;
 MAX_DESC = 64;
 MIN_EVENT = 100;

type
PRESTOREPTINFOA = ^_RESTOREPTINFOA;
_RESTOREPTINFOA = packed record
    dwEventType: DWORD;  // Type of Event - Begin or End
    dwRestorePtType: DWORD;  // Type of Restore Point - App install/uninstall
    llSequenceNumber: INT64;  // Sequence Number - 0 for begin
    szDescription: array [0..MAX_DESC] of CHAR; // Description - Name of Application / Operation
end;
RESTOREPOINTINFO = _RESTOREPTINFOA;
PRESTOREPOINTINFOA = ^_RESTOREPTINFOA;

PSMGRSTATUS = ^_SMGRSTATUS;
_SMGRSTATUS = packed record
    nStatus: DWORD; // Status returned by State Manager Process
    llSequenceNumber: INT64;  // Sequence Number for the restore point
end;
STATEMGRSTATUS =  _SMGRSTATUS;
PSTATEMGRSTATUS =  ^_SMGRSTATUS;

function SRSetRestorePointA(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus: PSTATEMGRSTATUS): Bool;
  stdcall; external 'SrClient.dll' Name 'SRSetRestorePointA';

// wywołanie
const
 CR = #13#10;
var
  RestorePtSpec: RESTOREPOINTINFO;
  SMgrStatus: STATEMGRSTATUS;
begin
      RestorePtSpec.dwEventType := END_SYSTEM_CHANGE;
      RestorePtSpec.dwRestorePtType  := CANCELLED_OPERATION;
      RestorePtSpec.llSequenceNumber := 6; // tutaj trzeba podać nr punktu do skasowania

      if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
        ShowMessage('Restore point canceled. Restore point data:' + CR+
        'Sequence Number: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR+
        'Status: ' + Format('%u', [SMgrStatus.nStatus]))
      else ShowMessage('Couldn''t cancel restore point.');
end;
0

a na MSDNie nie ma nic o tym?

P.S. nie sprawdzalem ale znalazlem cos takiego:
sciagnij komponent: http://www.msdn.microsoft.com/scripting/ i sprawdz ten kodik:

procedure TForm1.bnEnumClick(Sender: TObject);
var sr,srSet: OLEVAriant;
    i: integer;
begin
   ScriptControl1.Language := 'VBScript';
   srSet := ScriptControl1.Eval('GetObject("winmgmts:root/default").InstancesOf ("SystemRestore")');
   listbox1.items.add('Count: '+IntToStr(srSet.Count));
   for i := 0 to srSet.Count-1 do begin
      listbox1.Items.Add('No: '+IntToStr(i));
      try
         // somehow use the 'for each' here...
         // for each RP in RPSet
         //    wscript.Echo "Dir: RP" & RP.SequenceNumber & ", Name: " & RP.Description & ", Type: ", RP.RestorePointType & ", Time: " & RP.CreationTime
         // next
      except
         on e: exception do listbox1.Items.Add('- error: '+e.Message);
      end;
   end;
end;

znalezione na: http://64.233.183.104/search?[...]mp;ct=clnk&cd=1&gl=pl

0

Dzięki cimak :)

Instalacja komponentu była by najlepsza, ale nie wiem, czy jest sens...
Oprócz tego kodu Delphi, jest jeszcze skrypt w VBS.

Set RPSet = GetObject("winmgmts:root/default").InstancesOf ("SystemRestore")
for each RP in RPSet
    wscript.Echo "Dir: RP" & RP.SequenceNumber & ", Name: " & RP.Description & ", Type: ", RP.RestorePointType & ", Time: " & RP.CreationTime
next

Tylko teraz nie wiem, jak zmodyfikować ten kod, aby zapisywał wynik do pliku, a nie żeby pokazywał w komunikacie... dalej z odczytaniem będzie prosto.

//dodano

OK, poradziłem sobie. Listing jest zapisywany do pliku TXT.
Skrypt zapisać z rozszerzeniem VBS.

Option Explicit
Dim objFSO, objShell, objTextFile, objFile
Dim strFile, strText, RPSet, RP
strFile = "list_of_restore.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strFile)
set objFile = nothing
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 2
Set objTextFile = objFSO.OpenTextFile _
(strFile, ForAppending, True)

Set RPSet = GetObject("winmgmts:root/default").InstancesOf ("SystemRestore")
for each RP in RPSet
    strText = "Nr: " & RP.SequenceNumber & "  | Nazwa: " & RP.Description & "  | Index: " & RP.RestorePointType & "  | Data: " & RP.CreationTime
    objTextFile.WriteLine(strText)
next

objTextFile.Close
WScript.Quit

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0