unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TlHelp32, ExtCtrls, Menus, ImgList;
type
TForm5 =
class(TForm)
Image1: TImage;
Image2: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form5: TForm5;
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
implementation
{$R *.dfm}
//Programm Start
function processExists(exeFileName:
string): Boolean;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0
do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName)))
then
begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
// Abfrage ob Prozess aktiv ist (z.B. Notepad.exe)
procedure TForm5.Timer1Timer(Sender: TObject);
begin
if processExists('
notepad.exe')
then begin
Image1.visible:=True;
//rotes Image
Image2.visible:=False;
//grünes Image
end
else begin
Image1.visible:=False;
//rotes Image
Image2.visible:=True;
//grünes Image
end;
end;
end.