Lenguaje de programación Borland Delphi
Abajo mostramos el código fuente para crear un punto de restauración del sistema en Windows XP. Para ello necesitaremos un formulario y un botón:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
// Type of Event
BEGIN_SYSTEM_CHANGE = 100;
END_SYSTEM_CHANGE = 101;
// Type of Restore Points
APPLICATION_INSTALL = 0;
CANCELLED_OPERATION = 13;
MAX_DESC = 64;
MIN_EVENT = 100;
// Restore point information
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;
// Status returned by System Restore
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';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
CR = #13#10;
var
RestorePtSpec: RESTOREPOINTINFO;
SMgrStatus: STATEMGRSTATUS;
begin
// Initialize the RESTOREPOINTINFO structure
RestorePtSpec.dwEventType := BEGIN_SYSTEM_CHANGE;
RestorePtSpec.dwRestorePtType := APPLICATION_INSTALL;
RestorePtSpec.llSequenceNumber := 0;
RestorePtSpec.szDescription := 'Ejemplo de Punto de restauración del sistema';
if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
begin
ShowMessage('Punto de restauración creado con éxito. Datos:' + CR+
'Número de secuencia: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR+
'Estado: ' + Format('%u', [SMgrStatus.nStatus]));
// Restore Point Spec to cancel the previous restore point.
RestorePtSpec.dwEventType := END_SYSTEM_CHANGE;
RestorePtSpec.dwRestorePtType := CANCELLED_OPERATION;
RestorePtSpec.llSequenceNumber := SMgrStatus.llSequenceNumber;
end
else
ShowMessage('No se ha podido crear un punto de restauración del sistema.');
end;
end.
Publicado el: 2003-12-19