I found the following code in an article posted here recently. I thought
it would show all the processes running on my Windows 95 system. It
shows almost everything, except the one program I need to detect. Is
there a way to show EVERY process running in the background, no matter
how well hidden the program is? Specifically, I need to detect when
Skin98 is running. I'm sure there are other programs that are as well
hidden as Skin98, so I want to be able to detect those as well. A code
sample would be appreciated.
Code I'm using now:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, TLHELP32,
StdCtrls;
type
TForm1 = class(TForm)
sgModules: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
SortList: TStringList;
i: integer;
procedure GetModuleList(var List: TStringList);
var
i : integer;
SnapShotProc, SnapShotMod : THandle;
PE32 : TProcessEntry32;
ME32 : TModuleEntry32;
begin
List.Clear;
SnapShotProc := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (SnapShotProc = -1) then Exit;
PE32.dwSize := SizeOf(TProcessEntry32);
if Process32First(SnapShotProc, PE32) then
repeat
SnapShotMod := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
PE32.th32ProcessID);
if SnapShotMod <> -1 then
begin
ME32.dwSize := SizeOf(TModuleEntry32);
if Module32First(SnapShotMod, ME32) then
repeat
i:= List.Add(PE32.szExeFile + ' : ' + ME32.szExePath);
List.Objects[i] := pointer(ME32.th32ModuleID);
until not Module32Next(SnapShotMod, ME32);
end;
CloseHandle(SnapShotMod);
until not Process32Next(SnapShotProc, PE32);
CloseHandle(SnapShotProc);
end;
begin
try
SortList := TStringList.Create;
with sgModules do
begin
GetModuleList(SortList);
SortList.Sorted := true;
for i := 0 to Pred(SortList.Count) do
Items.Add(SortList[i]);
end;
finally
SortList.Free;
end;
end;
end.