一个笨办法是枚举所有进程:<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>但其实用我上面说的方法就可以了,没必要搞这么复杂。