Here's how to get a list of all the running processes (tasks) in Win95:
uses
TlHelp32;
{-------------------------------------------------------------------
Retrieves the first thread ID for the given process.
--------------------------------------------------------------------}
function GetProcessThread(const ProcessID : DWORD) : DWORD;
var
ThreadSnap : THandle;
ThreadEntry : TThreadEntry32;
begin
Result := 0;
// Take a snapshot of all threads in the specified process
ThreadSnap := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, ProcessID);
if ThreadSnap = -1 then
exit;
// Initialize size of structure
ThreadEntry.dwSize := sizeof(ThreadEntry);
// Loop through the threads and find the first one for this process
if Thread32First(ThreadSnap, ThreadEntry) then
repeat
if ThreadEntry.th32OwnerProcessID = ProcessID then
begin
Result := ThreadEntry.th32ThreadID;
break;
end;
until Thread32Next(ThreadSnap, ThreadEntry) = False;
CloseHandle(ThreadSnap);
end;
{-------------------------------------------------------------------
List the currently running processes
--------------------------------------------------------------------}
procedure ProcessList;
var
Snapshot : THandle;
ProcessEntry : TProcessEntry32;
begin
// Take a snapshot of all processes currently in the system
Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if SnapShot -1 then
begin
// Set size of PROCESSENTRY32 structure before use
ProcessEntry.dwSize := sizeof(ProcessEntry);
// Loop through all the processes in the snapshot
if Process32First(SnapShot, ProcessEntry) then
repeat
// Do something with each ProcessEntry
until Process32Next(SnapShot, ProcessEntry) = False;
CloseHandle(SnapShot);
end;
end;
{-------------------------------------------------------------------
Friendly way to kill the selected process.
Use TerminateProcess for a forcable way.
--------------------------------------------------------------------}
procedure KillProcess(ProcessID : DWORD);
var
ThreadID : DWORD;
begin
ThreadID := GetProcessThread(ProcessID);
PostThreadMessage(ThreadID, WM_QUIT, 0, 0);
end;
--- GoldED 2.41
---------------
* Origin: The Flying Circus BBS, Farmington Hills, MI. (1:2410/905)
|