delphi Windows 根据进程名结束进程的代码


本文整理自网络,侵删。

 
USES  TLHelp32;   //必须 Users 这个,FindProcessID 函数需要用到它。

{$R *.dfm}


function FindProcessID(s:string):integer;
var
  found,find:boolean;
  FSnapshotHandle:tHANDLE;
  lppe:TProcessEntry32;
begin
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照
  Find:=False;
  lppe.dwSize := Sizeof(lppe); //初始化
  found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信息
  while found do
      begin
      if LowerCase(ExtractFileName(lppe.szExeFile))=LowerCase(s) then
        begin
        Result:=lppe.th32ProcessID; //找到进程返回ID
        find:=true;
        CloseHandle(FSnapshotHandle);
        exit;
        end;
        found := Process32Next(FSnapshotHandle, lppe);
      end;
  CloseHandle(FSnapshotHandle);
  if find=False then
  Result:=0; //找不到进程返回0
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  ProH: THandle;
  ProcID: DWord;
begin
  ProcID := FindProcessID(Edit1.Text);

  ProH := OpenProcess(PROCESS_ALL_ACCESS, True, ProcID);
  TerminateProcess(ProH, 0);
end;

相关阅读 >>

Delphi�⒆执�传入到windows目前窗口cursor所在位置

Delphi 中文大写日期转换函数

Delphi检查getelementbyid返回值的有效性

Delphi stringtowidestring widestringtostring

Delphi程序禁止结束进程

Delphi将图片缩放成指定大小

Delphi 在tmemo中查找文本

Delphi 安卓添加资源图片并读取

Delphi 封装frame到dll文件

Delphi of 打坐与普通攻击calll调用

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



打赏

取消

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

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

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

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

评论

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