Unit ProcessInfoUnit

Uses
Classes, Interfaces, Objects and Records
Constants
Variables

Description

Tools for handling processes and retrieving execution information.

Overview

Functions and Procedures

function NormalizeExeName(const AName: string): string;
function IsProcessRunning(const AExeName: string): Boolean;
function FileTimeToDateTimeLocal(const AFileTime: TFileTime; out ADateTime: TDateTime): Boolean;
function GetProcessCreationTimeByPID(ANativePID: DWORD; out ACreationTime: TDateTime): Boolean;
function FindProcessStartForExe(const AExeName: string; out AStartTime: TDateTime; ACriteria: TProcessSelectionCriteria = pscOldest): Boolean;

Types

TProcessSelectionCriteria = (...);

Description

Functions and Procedures

function NormalizeExeName(const AName: string): string;

Normalizes an executable name by trimming spaces, converting to lowercase and ensuring the .exe extension is present.

Parameters
AName
The original executable name or path.
Returns

The normalized executable name.

function IsProcessRunning(const AExeName: string): Boolean;

Checks if a process with the given executable name is currently running.

Parameters
AExeName
The name of the executable (e.g., 'notepad.exe' or just 'notepad').
Returns

True if at least one instance of the process is found, False otherwise.

function FileTimeToDateTimeLocal(const AFileTime: TFileTime; out ADateTime: TDateTime): Boolean;

Converts a Windows TFileTime structure to a local TDateTime.

Parameters
@code(TFileTime)
The Windows file time structure.
ADateTime
Out parameter that receives the converted TDateTime.
Returns

True if conversion was successful, False otherwise.

function GetProcessCreationTimeByPID(ANativePID: DWORD; out ACreationTime: TDateTime): Boolean;

Retrieves the creation time of a process given its PID.

Parameters
ANativePID
The Native Process ID.
ACreationTime
Out parameter that receives the process creation time.
Returns

True if the information was successfully retrieved.

function FindProcessStartForExe(const AExeName: string; out AStartTime: TDateTime; ACriteria: TProcessSelectionCriteria = pscOldest): Boolean;

Finds the start time of a specific executable. If multiple instances are running, it selects one based on the ACriteria parameter.

Parameters
AExeName
The name of the executable to search for.
AStartTime
Out parameter that receives the found creation time.
ACriteria
The criteria used to select the instance (First, Oldest, Newest).
Returns

True if at least one instance was found and its time retrieved.

Types

TProcessSelectionCriteria = (...);

Criteria for selecting a process when multiple instances of the same executable name are running.

Values
  • pscFirstFound: Returns the first instance encountered in the process snapshot.
  • pscOldest: Returns the instance with the earliest creation date.
  • pscNewest: Returns the instance with the most recent creation date.