// This function is for Windows XP or higher. It restores the operating
// system to the specified 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.
// Number: the sequence number of the restore point to use.
// ListRestorePoints function returns available restore points.
// See "How to enumerate available system restore points?" topic.
// The method returns empty string on success and error description otherwise
function SystemRestore(Destination, UserName, Password: string; Number: integer): 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 := 'Restore';
Method.InParams.ParamByName('SequenceNumber').AsInteger := Number;
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;
|