Mega Code Archive

 
Categories / Delphi / Examples
 

How to find out if an application is running

Title: How to find out if an application is running Question: How can I find out what other applications are running? Answer: This is a modified version of Misha Moellner's KillTask() function. {For Windows 9x/ME/2000/XP } uses Tlhelp32; function IsAppRunning(ExeFileName: string): boolean; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin Result := false; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); while Integer(ContinueLoop) 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then Result := true; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end; Example: procedure TForm1.Button1Click(Sender: TObject); begin if IsAppRunning('notepad.exe') = true then showmessage(' App is running ') else showmessage(' App is not running ') end;