function GetProcessList(
out ProcessList: TProcessList): DWORD;
function GetOSVersionInfo(
var Info: TOSVersionInfo): Boolean;
begin
FillChar(Info, SizeOf(TOSVersionInfo), 0);
Info.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
Result := GetVersionEx(TOSVersionInfo(Addr(Info)^));
if (
not Result)
then
begin
FillChar(Info, SizeOf(TOSVersionInfo), 0);
Info.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
Result := GetVersionEx(TOSVersionInfo(Addr(Info)^));
if (
not Result)
then
Info.dwOSVersionInfoSize := 0;
end;
end;
var
OSInfo : TOSVersionInfo;
PidProcesses : PDWORD;
PidWork : PDWORD;
BufferSize : Cardinal;
cbNeeded : Cardinal;
cntProcesses : Cardinal;
i : Cardinal;
begin
result := 0;
// What OS are we running on?
if GetOSVersionInfo(OSInfo)
then
begin
if (OSInfo.dwPlatformId = VER_PLATFORM_WIN32_NT)
and (OSInfo.dwMajorVersion =
5)
then
// WinNT and higher
begin
cbNeeded := 0;
BufferSize := 0;
// how much memory do we need
if EnumProcesses(
nil, BufferSize, cbNeeded)
then
begin
cntProcesses := cbNeeded
div sizeof(DWORD);
GetMem(PidProcesses, cntProcesses);
if EnumProcesses(PidProcesses, cntProcesses, cbNeeded)
then
begin
PidWork := PidProcesses;
setlength(ProcessList, cntProcesses);
for i := 0
to cntProcesses - 1
do
begin
ProcessList[i] := PidWork^;
Inc(PidWork, sizeof(PDWORD));
end;
end;
FreeMem(PidProcesses, cntProcesses);
end;
end
// Win 9x and higher except WinNT
else
begin
end;
end;
end;