Jak utworzyć punkt przywracania systemu za pomocą Delphi (WinXP)
lofix
const
// wyjątki
BEGIN_SYSTEM_CHANGE = 100;
END_SYSTEM_CHANGE = 101;
// Punkt przywracania
APPLICATION_INSTALL = 0;
CANCELLED_OPERATION = 13;
MAX_DESC = 64;
MIN_EVENT = 100;
// Informacje o punkcie przywracania
type
PRESTOREPTINFOA = ^_RESTOREPTINFOA;
_RESTOREPTINFOA = packed record
dwEventType: DWORD; // wyjatek - poczatek lub koniec
dwRestorePtType: DWORD; // p.przywracania- App install/uninstall
llSequenceNumber: INT64;
szDescription: array [0..MAX_DESC] of CHAR; // Opis p.przywracania
end;
RESTOREPOINTINFO = _RESTOREPTINFOA;
PRESTOREPOINTINFOA = ^_RESTOREPTINFOA;
// Status zwracany przez p.przywracania
PSMGRSTATUS = ^_SMGRSTATUS;
_SMGRSTATUS = packed record
nStatus: DWORD; // status zwrocony przez manager procesów
llSequenceNumber: INT64;
end;
STATEMGRSTATUS = _SMGRSTATUS;
PSTATEMGRSTATUS = ^_SMGRSTATUS;
function SRSetRestorePointA(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus: PSTATEMGRSTATUS): Bool;
stdcall; external 'SrClient.dll' Name 'SRSetRestorePointA';
// Przykład użycia
// Ref: http://tinyurl.com/78pv
procedure TForm1.Button1Click(Sender: TObject);
const
CR = #13#10;
var
RestorePtSpec: RESTOREPOINTINFO;
SMgrStatus: STATEMGRSTATUS;
begin
// zainicjowanie RESTOREPOINTINFO
RestorePtSpec.dwEventType := BEGIN_SYSTEM_CHANGE;
RestorePtSpec.dwRestorePtType := APPLICATION_INSTALL;
RestorePtSpec.llSequenceNumber := 0;
RestorePtSpec.szDescription := 'Przykładowy punkt przywracania systemu utworzony w Delphi';
if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
begin
ShowMessage('Punkt przywracania utworzony. Data punktu przywracania :' + CR+
'Numer sekwencyjny: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR+
'Status: ' + Format('%u', [SMgrStatus.nStatus]));
// Skasowanie punktu przywracania
RestorePtSpec.dwEventType := END_SYSTEM_CHANGE;
RestorePtSpec.dwRestorePtType := CANCELLED_OPERATION;
RestorePtSpec.llSequenceNumber := SMgrStatus.llSequenceNumber;
if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
ShowMessage('Punkt przywracania usunieto. Data p.przywracania:' + CR+
'Numer sekwencyjny: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR+
'Status: ' + Format('%u', [SMgrStatus.nStatus]))
else
ShowMessage('Nie można usunąc punktu przywracania.');
end
else
ShowMessage('Nie można ustawić punktu przywracania.');
end;
end;
Zaczerpnięte z torry.net
Przyda się ;) Bravo!