Как получить список процессов?

Материал из DRKB

Как получить список процессов?[править | править код]

Эта функция возвращает результат: запущено ли приложение, переданное ей в качестве параметра. Функция просматривает список всех процессов и делает вывод.

function IsRunning(sName: string): Boolean; 
var 
  han: THandle; 
  ProcStruct: PROCESSENTRY32; // from "tlhelp32" in uses clause 
  sID: string; 
begin 
  Result := False; 
  // Get a snapshot of the system 
  han := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); 
  if han = 0 then 
    exit; 
  // Loop thru the processes until we find it or hit the end 
  ProcStruct.dwSize := SizeOf(PROCESSENTRY32); 
  if Process32First(han, ProcStruct) then 
  begin 
    repeat 
      sID := ExtractFileName(ProcStruct.szExeFile); 
      // Check only against the portion of the name supplied, ignoring case 
      if UpperCase(Copy(sId, 1, Length(sName))) = UpperCase(sName) then 
      begin 
        // Report we found it 
        Result := True; 
        Break; 
      end; 
    until not Process32Next(han, ProcStruct); 
  end; 
  // clean-up 
  CloseHandle(han); 
end;


Author: Song
Source: Взято из http://forum.sources.ru
ID: 02045