// This function lists system restore points. It is for Windows XP or higher.
// It may be used for local or remote host. When used for local host
// the first three parameters must be empty.
// For remote computer the 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
// AList: receives the list of existing restore points
procedure ListRestorePoints(TargetHost, UserName, Password: string; AList: TStrings);
var
Connection: TWmiConnection;
Query: TWmiQuery;
begin
Query := TWmiQuery.Create(nil);
Connection := TWmiConnection.Create(nil);
try
Query.Connection := Connection;
Query.WQL.Text := 'select * from SystemRestore';
Connection.MachineName := TargetHost;
Connection.NameSpace := 'root\default';
Connection.Credentials.UserName := UserName;
Connection.Credentials.Password := Password;
try
// exception may happen on Win9x, WinNT if WMI core is not installed;
// The provided credentials may also be invalid.
Connection.Connected := true;
except
writeln('Cannot connect to the destination host');
Exit;
end;
Query.Open;
while not Query.EOF do
begin
AList.Add(
Query.FieldByName('SequenceNumber').AsString + ': ' +
DateTimeToStr(WmiParseDateTime(Query.FieldByName('CreationTime').AsString)) + ' ' +
Query.FieldByName('Description').AsString);
Query.Next;
end;
finally
Query.Free;
Connection.Free;
end;
end;
|