const
RESTORE_TYPE_APPLICATION_INSTALL = 0;
RESTORE_TYPE_APPLICATION_UNINSTALL = 1;
RESTORE_TYPE_CHECKPOINT = 7;
RESTORE_TYPE_DEVICE_DRIVER_INSTALL = 10;
RESTORE_TYPE_MODIFY_SETTINGS = 12;
RESTORE_TYPE_CANCELLED_OPERATION = 13;
EVENT_TYPE_BEGIN_NESTED_SYSTEM_CHANGE = 102;
EVENT_TYPE_BEGIN_SYSTEM_CHANGE = 100;
EVENT_TYPE_END_NESTED_SYSTEM_CHANGE = 103;
EVENT_TYPE_END_SYSTEM_CHANGE = 101;
// This function is for Windows XP or higher. It creates a new system restore
// point. It may be used for local or remote host. When used for local host
// Destination, UserName and Password parameters must be empty.
// For remote computer, parameters must be:
// TargetHost: name or IP address of the remote host, like '10.8.36.54'
// UserName: name of the user, may include domain, like 'MOON\Administrator';
// Password: the user's password.
// description: the description of the restore point how it will later appear in
// the user interface.
// The method returns empty string on success and error description otherwise
function CreateSystemRestorePoint(Destination, UserName, Password, Description: string): string;
var
Connection: TWmiConnection;
Method: TWmiMethod;
begin
Result := '';
Connection := TWmiConnection.Create(nil);
Method := TWmiMethod.Create(nil);
try
try
Connection.MachineName := Destination;
Connection.NameSpace := 'root\default';
Connection.Credentials.UserName := UserName;
Connection.Credentials.Password := Password;
Connection.ObjectPath := 'SystemRestore';
Connection.Connected := true;
Method.WmiObjectSource := Connection;
Method.WmiMethodName := 'CreateRestorePoint';
with Method.InParams do
begin
ParamByName('Description').AsString := Description;
ParamByName('EventType').AsInteger := EVENT_TYPE_BEGIN_SYSTEM_CHANGE;
ParamByName('RestorePointType').AsInteger := RESTORE_TYPE_CHECKPOINT;
end;
if Method.Execute <> 0 then
begin
Result := Method.LastWmiErrorDescription;
if Result = '' then Result := 'Error ' + IntToStr(Method.LastWmiError);
end;
finally
Method.Free;
Connection.Free;
end;
except
on E: Exception do Result := E.Message;
end;
end;
|