unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ComCtrls, StdCtrls, ExtCtrls;<br><br>type<br><br><br> TForm1 = class(TForm)<br> ListBox1: TListBox;<br> Panel1: TPanel;<br> Button2: TButton;<br> ListBox2: TListBox;<br> Splitter1: TSplitter;<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br>uses psapi;<br>{$R *.DFM}<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>type<br>integer = DWORD; // different versions of psapi.pas floating around<br>var<br> i,j,pidNeeded,modNeeded : Integer;<br> PIDList : array[0..1000] of Integer; // 1000 should be enough<br> MODList : array[0..1000] of HInst;<br> PIDName : array [0..MAX_PATH - 1] of char;<br> MODName : array [0..MAX_PATH - 1] of char;<br> PH : THandle;<br>begin<br><br> // fill an array with process ids<br> if not enumprocesses (@PIDList, 1000, pidNeeded) then<br> begin<br> ListBox1.Items.Add('Need psapi.dll');<br> exit;<br> end;<br><br> // now open each process and its modules<br> for i := 0 to (pidNeeded div sizeof (Integer)- 1) do<br> begin<br> // get a handle to the process<br> PH := OpenProcess (PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,<br> PIDList);<br><br> if PH <> 0 then<br> begin<br> // print the process name<br> if GetModuleBaseName (PH, 0, PIDName, sizeof (PIDName)) > 0 then<br> begin<br> ListBox1.Items.Add('process : ' + PIDName);<br><br> // fill an array of modules associated with this process<br> if not EnumProcessModules (PH,@MODList,1000, modNeeded) then modNeeded:= 0;<br><br> // print the modules in the list<br> for j := 0 to (modNeeded div sizeof (hInst) - 1) do<br> if GetModuleFileNameEx (PH, MODList[j], MODName,sizeof(MODName)) > 0 then<br> begin<br> ListBox1.Items.Add(' module: ' + MODName);<br> if LowerCase(trim(ExtractFileName(ModName))) = LowerCase('MHK.dll') then Caption := ('Keyboard hook already running'); //注意这里<br> end;<br> if PH > 0 then CloseHandle(PH);<br> end;<br> end;<br> end;<br> <br>end;<br><br>end.<br>