Когда мое приложение начинало работать?

SELECT * INTO < new_table > FROM < existing_table > WHERE < clause >
8
задан Rob Kennedy 13 November 2009 в 06:36
поделиться

4 ответа

You can use the Windows API call to GetProcessTimes (declared in Windows.pas) to get details for any process.

If it's your application, I would probably get the start time myself and log it somewhere to keep a history.

15
ответ дан 5 December 2019 в 07:35
поделиться

Используйте NtQuerySystemInformation с информационным классом SystemProcessInformation, это возвращает массив структур (записей) SYSTEM_PROCESSES, из которых CreateTime содержит точное время, когда приложения были запущены:

  _SYSTEM_PROCESSES = record // Information Class 5
    NextEntryDelta: ULONG;
    ThreadCount: ULONG;
    Reserved1: array[0..5] of ULONG;
    CreateTime: LARGE_INTEGER;
    UserTime: LARGE_INTEGER;
    KernelTime: LARGE_INTEGER;
    ProcessName: UNICODE_STRING;
    BasePriority: KPRIORITY;
    ProcessId: ULONG;
    InheritedFromProcessId: ULONG;
    HandleCount: ULONG;
    // next two were Reserved2: array [0..1] of ULONG; thanks to Nico Bendlin
    SessionId: ULONG;
    Reserved2: ULONG;
    VmCounters: VM_COUNTERS;
    PrivatePageCount: ULONG;
    IoCounters: IO_COUNTERSEX; // Windows 2000 only
    Threads: array[0..0] of SYSTEM_THREADS;
  end;
  SYSTEM_PROCESSES = _SYSTEM_PROCESSES;
  PSYSTEM_PROCESSES = ^SYSTEM_PROCESSES;
  TSystemProcesses = SYSTEM_PROCESSES;
  PSystemProcesses = PSYSTEM_PROCESSES;

Мы уже перевели все это в Jedi Apilib (JwaNative)

2
ответ дан 5 December 2019 в 07:35
поделиться

I'm not sure if there's a function or API call for this. But you can fake it pretty easily. Create a unit that looks like this:

unit AppStartTime;

interface

function GetAppStartTime: TDateTime;

implementation
uses
  SysUtils;

var
  fStartTime: TDateTime;

function GetAppStartTime: TDateTime;
begin
  result := fStartTime;
end;

initialization
  fStartTime := Now;

end.

Add it to your DPR's uses list, at the top, either first or immediately after anything that "must be first on the list", such as a custom memory manager.

4
ответ дан 5 December 2019 в 07:35
поделиться

You can have your app log the startup time to a text file or database either in the DPR file or in your main form's OnCreate() event. You can use Delphi's Now() function to get the current date and time, and format it as a string using FormatDateTime() or DateTimeToStr(), depending on what exactly you're looking to do.

The code below saves the startup date and time during the main form's constructor to a text file in the same folder as the application itself called StartDateTime.txt:

procedure TForm1.FormCreate(Sender: TObject);
var
  SL: TStringList;
begin
  SL := TStringList.Create;
  try
    SL.Add(FormatDateTime('mm/dd/yyyy hh:nn:ss', Now());
    SL.SaveToFile(ExtractFilePath(ParamStr(0)) + 'StartDateTime.txt');
  finally
    SL.Free;
  end;
end;
1
ответ дан 5 December 2019 в 07:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: