以下代码都在相应的环境中运行过,可用:
用delphi代码编写显示当前进程列表的代码:
please use delphi language to list current process name .
delphi代码如下:
uses
TlHelp32, Windows;
function GetProcessList: TStringList;
var
SnapshotHandle: THandle;
ProcessEntry32: TProcessEntry32;
ProcessList: TStringList;
begin
ProcessList := TStringList.Create;
SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if SnapshotHandle <> INVALID_HANDLE_VALUE then
begin
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
if Process32First(SnapshotHandle, ProcessEntry32) then
begin
repeat
ProcessList.Add(ProcessEntry32.szExeFile);
until not Process32Next(SnapshotHandle, ProcessEntry32);
end;
CloseHandle(SnapshotHandle);
end;
Result := ProcessList;
end;
var
ProcessList: TStringList;
begin
ProcessList := GetProcessList;
try
Writeln('List of running processes:');
Writeln(ProcessList.Text);
finally
ProcessList.Free;
end;
end.