Unit find_unit;
Interface
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Tlhelp32, Comctrls
type TFindForm = class (TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; SB: TStatusBar; Label1: TLabel; Label2: TLabel; procedure Button1Click (Sender: TObject); private {Private declarations} public {Public declarations} function FindProc (procname: string): boolean;
Var Findform: Tfindform;
IMPLEMENTATION
{$ R * .dfm}
procedure TFindForm.Button1Click (Sender: TObject); var hFile: THandle; r: Boolean; tf: string; begin r: = False; hFile: = CreateFile (PChar (Edit1.Text), Generic_Read or Generic_Write, File_Share_Read or File_Share_Write, nil , Open_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if Hfile <> invalid_handle_value dam closehandle (hfile); r: = true; end; if r1en sb.panels [0] .text: = 'space find!' Else sb.panels [ 0] .text: = 'Space Not Found!'; TF: = Edit2.Text; if POS ('.', TF) = 0 THEN TF: = Tf '.exe'; if FindProc (TF) THEN SB. PANELS [1] .text: = 'process find!' Else sb.panels [1] .text: = 'process not found!';
function TFindForm.FindProc (ProcName: string): boolean; var OK: Bool; hPL, hML: THandle; ProcessStruct: TProcessEntry32; ModuleStruct: TModuleEntry32; begin Result: = False; hPL: = CreateToolHelp32SnapShot (TH32CS_SNAPPROCESS, 0); ProcessStruct.dwSize : = SizeOf (TProcessEntry32); OK: = Process32First (hPL, ProcessStruct); while OK do begin if UpperCase (ProcessStruct.szExeFile) = UpperCase (ProcName) then begin Result: = True; // find path info hML: = CreateToolhelp32Snapshot ( TH32CS_SNAPMODULE, ProcessStruct.th32ProcessID); ModuleStruct.dwSize: = SizeOf (TModuleEntry32); Module32First (hML, ModuleStruct); if hML> 0 then begin ShowMessage (ModuleStruct.szExePath); end; CloseHandle (hML); end; OK: = Process32Next (HPL, ProcessStruct); end; closehandle (hpl); end; end.