2014-09-16 17:28:22 +03:00
|
|
|
unit uSysCtrls;
|
2014-08-31 20:11:20 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////
|
2014-09-16 17:28:22 +03:00
|
|
|
/// Lina System Controls Unit ///
|
2014-08-31 20:11:20 +03:00
|
|
|
/// **************************** ///
|
|
|
|
/// (c) 2014 Dennis G�hlert a.o. ///
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{ Standard-Units }
|
2014-09-22 00:54:48 +03:00
|
|
|
SysUtils, Classes, Windows, ExtCtrls, TlHelp32, PsAPI,
|
2014-08-31 20:11:20 +03:00
|
|
|
{ Andere Package-Units }
|
2014-09-05 02:16:55 +03:00
|
|
|
uBase, uSysTools;
|
2014-08-31 20:11:20 +03:00
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
type
|
|
|
|
{ Fehlermeldungen }
|
|
|
|
EBatteryFlag = class(Exception);
|
|
|
|
|
2014-08-31 20:11:20 +03:00
|
|
|
type
|
|
|
|
{ Hilfsklassen }
|
|
|
|
TBatteryFlag = (bfHealthy,bfLow,bfCritical,bfCharge,bfHealthyAccu,bfNone,bfUnknown);
|
|
|
|
TBatteryStatus = (bsInternal,bsExternal);
|
2014-09-22 00:54:48 +03:00
|
|
|
TProcessRefreshMode = (prNone,prAccess,prTime);
|
2014-08-31 20:11:20 +03:00
|
|
|
|
|
|
|
type
|
2014-09-16 17:28:22 +03:00
|
|
|
{ Hauptklassen }
|
2014-08-31 20:11:20 +03:00
|
|
|
TBattery = class(TComponent)
|
|
|
|
private
|
|
|
|
{ Private-Deklarationen }
|
2014-09-05 02:16:55 +03:00
|
|
|
FAbout: TComponentAbout;
|
2014-08-31 20:11:20 +03:00
|
|
|
protected
|
|
|
|
{ Protected-Deklarationen }
|
2014-09-05 02:16:55 +03:00
|
|
|
function BatteryFlag(Flag: Integer): TBatteryFlag;
|
2014-08-31 20:11:20 +03:00
|
|
|
public
|
|
|
|
{ Public-Deklarationen }
|
2014-09-09 15:46:12 +03:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
2014-08-31 20:11:20 +03:00
|
|
|
function GetPowerStatus: TBatteryStatus;
|
|
|
|
function GetBatteryTime: TDateTime;
|
|
|
|
function GetBatteryFullTime: TDateTime;
|
|
|
|
function GetBatteryFlag: TBatteryFlag;
|
|
|
|
function GetBatteryFlagReport: String;
|
|
|
|
function GetBatteryPercent: Byte;
|
|
|
|
published
|
|
|
|
{ Published-Deklarationen }
|
2014-09-05 02:16:55 +03:00
|
|
|
property About: TComponentAbout read FAbout;
|
2014-08-31 20:11:20 +03:00
|
|
|
end;
|
|
|
|
|
2014-09-16 17:28:22 +03:00
|
|
|
TCursorFix = class(TComponent)
|
|
|
|
private
|
|
|
|
{ Private-Deklarationen }
|
|
|
|
FAbout: TComponentAbout;
|
|
|
|
public
|
|
|
|
{ Public-Deklarationen }
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
published
|
|
|
|
{ Published-Deklarationen }
|
|
|
|
property About: TComponentAbout read FAbout;
|
|
|
|
end;
|
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
TProcessManager = class(TComponent)
|
|
|
|
private
|
|
|
|
{ Private-Deklarationen }
|
2014-09-22 00:54:48 +03:00
|
|
|
TimerObject: TTimer;
|
2014-09-21 21:16:51 +03:00
|
|
|
FAbout: TComponentAbout;
|
|
|
|
FNames: TStrings;
|
|
|
|
FTimeOut: DWORD;
|
2014-09-22 00:54:48 +03:00
|
|
|
FRefreshMode: TProcessRefreshMode;
|
|
|
|
{ Methoden }
|
|
|
|
function GetNames: TStrings;
|
|
|
|
procedure SetRefreshMode(Value: TProcessRefreshMode);
|
|
|
|
function GetInterval: Cardinal;
|
|
|
|
procedure SetInterval(Value: Cardinal);
|
|
|
|
procedure TimerObjectTimer(Sender: TObject);
|
2014-09-21 21:16:51 +03:00
|
|
|
public
|
|
|
|
{ Public-Deklarationen }
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure Update;
|
|
|
|
procedure Kill(ProcID: DWORD);
|
|
|
|
function GetID(ProcName: String): DWORD;
|
|
|
|
function GetPath(ProcID: DWORD): String;
|
|
|
|
function GetThreads(ProcName: String): DWORD;
|
|
|
|
function GetParentID(ProcName: String): DWORD;
|
|
|
|
function GetPriority(ProcName: String): Integer;
|
|
|
|
function GetMemory(ProcID: DWORD): DWORD;
|
2014-10-09 04:07:17 +03:00
|
|
|
property Names: TStrings read GetNames;
|
2014-09-21 21:16:51 +03:00
|
|
|
published
|
|
|
|
{ Published-Deklarationen }
|
|
|
|
property About: TComponentAbout read FAbout;
|
|
|
|
property TimeOut: DWORD read FTimeOut write FTimeOut;
|
2014-09-22 00:54:48 +03:00
|
|
|
property RefreshMode: TProcessRefreshMode read FRefreshMode write SetRefreshMode default prNone;
|
|
|
|
property Interval: Cardinal read GetInterval write SetInterval default 1000;
|
2014-09-21 21:16:51 +03:00
|
|
|
end;
|
|
|
|
|
2014-08-31 20:11:20 +03:00
|
|
|
procedure Register;
|
|
|
|
|
|
|
|
const
|
|
|
|
{ PowerStatus-Meldungen }
|
|
|
|
PS_HEALTHY = 'Healthy';
|
|
|
|
PS_LOW = 'Low';
|
|
|
|
PS_CRITICAL = 'Critical';
|
|
|
|
PS_CHARGE = 'Charge';
|
2014-09-05 02:16:55 +03:00
|
|
|
PS_HEALTHYACCU = 'HealthyAccu';
|
2014-08-31 20:11:20 +03:00
|
|
|
PS_NONE = 'None';
|
|
|
|
PS_UNKNOWN = 'Unknown';
|
2014-09-16 17:28:22 +03:00
|
|
|
{ Meta-Daten }
|
|
|
|
BatteryComponent_Name = 'Battery';
|
|
|
|
BatteryComponent_Version = 1.0;
|
|
|
|
BatteryComponent_Copyright = 'Copyright � 2014';
|
|
|
|
BatteryComponent_Author = 'Dennis G�hlert a.o.';
|
|
|
|
|
|
|
|
CursorFixComponent_Name = 'CursorFix';
|
|
|
|
CursorFixComponent_Version = 1.0;
|
|
|
|
CursorFixComponent_Copyright = 'Copyright � 2014';
|
|
|
|
CursorFixComponent_Author = 'Dennis G�hlert a.o.';
|
2014-08-31 20:11:20 +03:00
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
ProcessManagerComponent_Name = 'ProcessManager';
|
|
|
|
ProcessManagerComponent_Version = 1.0;
|
|
|
|
ProcessManagerComponent_Copyright = 'Copyright � 2014';
|
|
|
|
ProcessManagerComponent_Author = 'Dennis G�hlert a.o.';
|
|
|
|
|
2014-08-31 20:11:20 +03:00
|
|
|
implementation
|
|
|
|
|
|
|
|
procedure Register;
|
|
|
|
begin
|
2014-09-21 21:16:51 +03:00
|
|
|
RegisterComponents(ComponentsPage,[TBattery,TCursorFix,TProcessManager]);
|
2014-08-31 20:11:20 +03:00
|
|
|
end;
|
|
|
|
|
2014-09-16 17:28:22 +03:00
|
|
|
{ ----------------------------------------------------------------------------
|
|
|
|
TBattery
|
|
|
|
---------------------------------------------------------------------------- }
|
|
|
|
|
2014-08-31 20:11:20 +03:00
|
|
|
function TBattery.BatteryFlag(Flag: Integer): TBatteryFlag;
|
|
|
|
begin
|
|
|
|
case Flag of
|
|
|
|
1: Result := bfHealthy;
|
|
|
|
2: Result := bfLow;
|
|
|
|
4: Result := bfCritical;
|
|
|
|
8: Result := bfCharge;
|
|
|
|
9: Result := bfHealthyAccu;
|
|
|
|
128: Result := bfNone;
|
|
|
|
255: Result := bfUnknown;
|
2014-09-21 21:16:51 +03:00
|
|
|
else
|
|
|
|
begin
|
|
|
|
raise EBatteryFlag.Create('Unable to obtain battery flag information');
|
|
|
|
end;
|
2014-08-31 20:11:20 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-09-09 15:46:12 +03:00
|
|
|
constructor TBattery.Create(AOwner: TComponent);
|
2014-08-31 20:11:20 +03:00
|
|
|
begin
|
2014-09-09 15:46:12 +03:00
|
|
|
inherited;
|
2014-09-05 02:16:55 +03:00
|
|
|
FAbout := TComponentAbout.Create(BatteryComponent_Name,BatteryComponent_Version,BatteryComponent_Copyright,BatteryComponent_Author);
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TBattery.Destroy;
|
|
|
|
begin
|
|
|
|
FAbout.Free;
|
2014-09-09 15:46:12 +03:00
|
|
|
inherited;
|
2014-08-31 20:11:20 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetPowerStatus: TBatteryStatus;
|
|
|
|
var
|
|
|
|
SysPowerStatus: TSystemPowerStatus;
|
|
|
|
begin
|
|
|
|
GetSystemPowerStatus(SysPowerStatus);
|
|
|
|
if Boolean(SysPowerStatus.ACLineStatus) then
|
|
|
|
begin
|
|
|
|
Result := bsExternal;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
Result := bsInternal;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetBatteryTime: TDateTime;
|
|
|
|
var
|
|
|
|
SysPowerStatus: TSystemPowerStatus;
|
|
|
|
begin
|
|
|
|
GetSystemPowerStatus(SysPowerStatus);
|
|
|
|
Result := SecToTime(SysPowerStatus.BatteryLifeTime);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetBatteryFlag: TBatteryFlag;
|
|
|
|
var
|
|
|
|
SysPowerStatus: TSystemPowerStatus;
|
|
|
|
begin
|
|
|
|
GetSystemPowerStatus(SysPowerStatus);
|
|
|
|
Result := BatteryFlag(SysPowerStatus.BatteryFlag);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetBatteryFlagReport: String;
|
|
|
|
begin
|
|
|
|
case GetBatteryFlag of
|
|
|
|
bfHealthy: Result := PS_HEALTHY;
|
|
|
|
bfLow: Result := PS_LOW;
|
|
|
|
bfCritical: Result := PS_CRITICAL;
|
|
|
|
bfCharge: Result := PS_CHARGE;
|
|
|
|
bfHealthyAccu: Result := PS_HEALTHYACCU;
|
|
|
|
bfNone: Result := PS_NONE;
|
|
|
|
bfUnknown: Result := PS_UNKNOWN;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetBatteryPercent: Byte;
|
|
|
|
var
|
|
|
|
SysPowerStatus: TSystemPowerStatus;
|
|
|
|
begin
|
|
|
|
GetSystemPowerStatus(SysPowerStatus);
|
|
|
|
Result := SysPowerStatus.BatteryLifePercent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBattery.GetBatteryFullTime: TDateTime;
|
|
|
|
var
|
|
|
|
SysPowerStatus: TSystemPowerStatus;
|
|
|
|
begin
|
|
|
|
GetSystemPowerStatus(SysPowerStatus);
|
|
|
|
Result := SecToTime(SysPowerStatus.BatteryFullLifeTime);
|
|
|
|
end;
|
|
|
|
|
2014-09-16 17:28:22 +03:00
|
|
|
{ ----------------------------------------------------------------------------
|
|
|
|
TCursorFix
|
|
|
|
---------------------------------------------------------------------------- }
|
|
|
|
|
|
|
|
constructor TCursorFix.Create(AOwner: TComponent);
|
|
|
|
{$IFDEF NO_CURSOR}
|
|
|
|
var
|
|
|
|
CursorHandle: THandle;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FAbout := TComponentAbout.Create(CursorFixComponent_Name,CursorFixComponent_Version,CursorFixComponent_Copyright,CursorFixComponent_Author);
|
|
|
|
{$IFDEF NO_CURSOR}
|
|
|
|
CursorHandle := Screen.Cursors[crHandPoint];
|
|
|
|
Screen.Cursors[crHandPoint] := LoadCursor(0,IDC_HAND);
|
|
|
|
DestroyCursor(CursorHandle);
|
|
|
|
{$ELSE}
|
|
|
|
{$MESSAGE WARN 'TCursorFix component has been created but not initialized due to the current IDE version'}
|
|
|
|
OutputDebugString('TCursorFix component has been created but not initialized due to the current IDE version');
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TCursorFix.Destroy;
|
|
|
|
{$IFDEF NO_CURSOR}
|
|
|
|
var
|
|
|
|
CursorHandle: THandle;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
FAbout.Free;
|
|
|
|
{$IFDEF NO_CURSOR}
|
|
|
|
CursorHandle := Screen.Cursors[crHandPoint];
|
|
|
|
Screen.Cursors[crHandPoint] := LoadCursor(0,IDC_HANDPT);
|
|
|
|
DestroyCursor(CursorHandle);
|
|
|
|
{$ENDIF}
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
{ ----------------------------------------------------------------------------
|
|
|
|
TProcessManager
|
|
|
|
---------------------------------------------------------------------------- }
|
|
|
|
|
|
|
|
constructor TProcessManager.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FAbout := TComponentAbout.Create(ProcessManagerComponent_Name,ProcessManagerComponent_Version,ProcessManagerComponent_Copyright,ProcessManagerComponent_Author);
|
|
|
|
FNames := TStringList.Create;
|
2014-09-22 00:54:48 +03:00
|
|
|
TimerObject := TTimer.Create(Self);
|
|
|
|
FRefreshMode := prNone;
|
|
|
|
TimerObject.OnTimer := TimerObjectTimer;
|
2014-09-21 21:16:51 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TProcessManager.Destroy;
|
|
|
|
begin
|
|
|
|
FAbout.Free;
|
|
|
|
FNames.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2014-09-22 00:54:48 +03:00
|
|
|
function TProcessManager.GetNames: TStrings;
|
|
|
|
begin
|
|
|
|
if FRefreshMode = prAccess then
|
|
|
|
begin
|
|
|
|
Update;
|
|
|
|
end;
|
|
|
|
Result := FNames;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TProcessManager.SetRefreshMode(Value: TProcessRefreshMode);
|
|
|
|
begin
|
|
|
|
FRefreshMode := Value;
|
|
|
|
TimerObject.Enabled := (Value = prTime);
|
|
|
|
end;
|
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
procedure TProcessManager.Update;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ProcEntry: TProcessEntry32;
|
|
|
|
begin
|
|
|
|
FNames.Clear;
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
|
try
|
|
|
|
ProcEntry.dwSize := SizeOf(ProcEntry);
|
2014-09-22 00:54:48 +03:00
|
|
|
if Process32First(Snapshot,ProcEntry) = True then
|
2014-09-21 21:16:51 +03:00
|
|
|
begin
|
|
|
|
repeat
|
|
|
|
FNames.Add(ProcEntry.szExeFile);
|
|
|
|
until (Process32Next(Snapshot,ProcEntry) = False)
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-09-22 00:54:48 +03:00
|
|
|
function TProcessManager.GetInterval: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := TimerObject.Interval;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TProcessManager.SetInterval(Value: Cardinal);
|
|
|
|
begin
|
|
|
|
TimerObject.Interval := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TProcessManager.TimerObjectTimer(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Update;
|
|
|
|
end;
|
|
|
|
|
2014-09-21 21:16:51 +03:00
|
|
|
procedure TProcessManager.Kill(ProcID: DWORD);
|
|
|
|
var
|
|
|
|
CurrentProc: THandle;
|
|
|
|
Error: DWORD;
|
|
|
|
begin
|
|
|
|
CurrentProc := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE,False,ProcID);
|
|
|
|
try
|
|
|
|
if CurrentProc > 0 then
|
|
|
|
begin
|
|
|
|
Error := Integer(TerminateProcess(CurrentProc,1));
|
|
|
|
if Error <> 0 then
|
|
|
|
begin
|
|
|
|
Error := WaitForSingleObject(CurrentProc,FTimeOut);
|
|
|
|
if Error = WAIT_FAILED then
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(CurrentProc);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetID(ProcName: String): DWORD;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ProcEntry: TProcessEntry32;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
|
try
|
|
|
|
ProcEntry.dwSize := SizeOf(ProcEntry);
|
|
|
|
if Process32First(Snapshot,ProcEntry) then
|
|
|
|
begin
|
|
|
|
repeat
|
|
|
|
if Pos(AnsiLowerCase(ProcEntry.szExeFile),AnsiLowerCase(ExtractFilename(ProcName))) > 0 then
|
|
|
|
begin
|
|
|
|
Result := ProcEntry.th32ProcessID;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
until (Process32Next(Snapshot,ProcEntry) = False)
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetPath(ProcID: DWORD): String;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ModEntry: TModuleEntry32;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPMODULE,ProcID);
|
|
|
|
try
|
|
|
|
ModEntry.dwSize := SizeOf(ModEntry);
|
|
|
|
if Module32First(Snapshot,ModEntry) then
|
|
|
|
begin
|
|
|
|
Result := ModEntry.szExePath;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetThreads(ProcName: String): DWORD;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ProcEntry: TProcessEntry32;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
|
try
|
|
|
|
ProcEntry.dwSize := SizeOf(ProcEntry);
|
|
|
|
if Process32First(Snapshot,ProcEntry) then
|
|
|
|
begin
|
|
|
|
repeat
|
|
|
|
if Pos(AnsiLowerCase(ProcEntry.szExeFile),AnsiLowerCase(ExtractFilename(ProcName))) > 0 then
|
|
|
|
begin
|
|
|
|
Result := ProcEntry.cntThreads;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
until (Process32Next(Snapshot,ProcEntry) = False)
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetParentID(ProcName: String): DWORD;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ProcEntry: TProcessEntry32;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
|
try
|
|
|
|
ProcEntry.dwSize := SizeOf(ProcEntry);
|
|
|
|
if Process32First(Snapshot,ProcEntry) then
|
|
|
|
begin
|
|
|
|
repeat
|
|
|
|
if Pos(AnsiLowerCase(ProcEntry.szExeFile),AnsiLowerCase(ExtractFilename(ProcName))) > 0 then
|
|
|
|
begin
|
|
|
|
Result := ProcEntry.th32ParentProcessID;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
until (Process32Next(Snapshot,ProcEntry) = False)
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetPriority(ProcName: String): Integer;
|
|
|
|
var
|
|
|
|
Snapshot: THandle;
|
|
|
|
ProcEntry: TProcessEntry32;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
Snapshot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
|
try
|
|
|
|
ProcEntry.dwSize := SizeOf(ProcEntry);
|
|
|
|
if Process32First(Snapshot,ProcEntry) then
|
|
|
|
begin
|
|
|
|
repeat
|
|
|
|
if Pos(AnsiLowerCase(ProcEntry.szExeFile),AnsiLowerCase(ExtractFilename(ProcName))) > 0 then
|
|
|
|
begin
|
|
|
|
Result := ProcEntry.pcPriClassBase;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
until (Process32Next(Snapshot,ProcEntry) = False)
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
CloseHandle(Snapshot);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TProcessManager.GetMemory(ProcID: DWORD): DWORD;
|
|
|
|
var
|
2014-09-22 00:54:48 +03:00
|
|
|
ProcMem: TProcessMemoryCounters;
|
2014-09-21 21:16:51 +03:00
|
|
|
begin
|
|
|
|
Result := 0;
|
2014-09-22 00:54:48 +03:00
|
|
|
ProcMem.cb := SizeOf(ProcMem);
|
|
|
|
if GetProcessMemoryInfo(OpenProcess(PROCESS_QUERY_INFORMATION,False,ProcID),@ProcMem,SizeOf(ProcMem)) = True then
|
|
|
|
begin
|
|
|
|
Result := ProcMem.WorkingSetSize;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
RaiseLastOSError;
|
2014-09-21 21:16:51 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-08-31 20:11:20 +03:00
|
|
|
end.
|