delphi 查找一个特定的EXE是否在内存中运行


本文整理自网络,侵删。

 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;
  end;

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 then
     begin
       CloseHandle(hFile);
       r := True;
     end;
  if r
     then 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!';
end;

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. 

相关阅读 >>

Delphi android 按包名判断是否安装了app

tidhttpresponseinfo 中文乱码问题解决

Delphi 在windows平台下实现进程隐藏

Delphi与进程、窗口句柄、文件属性、程序运行状态

Delphi idhttp控件断点下载

Delphi android服务向导

Delphi xe 跨平台(windows、android安卓、苹果macos、苹果ios)写法

Delphi try abort、exit except 、finally end 执行情况

Delphi listview 设置固定列宽

Delphi 限制文本框中只接受数字

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...