delphi StopProcess 进程关闭函数


本文整理自网络,侵删。

 
单元:TlHelp32

function StopProcess(ExeFileName: string): Integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := 0;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  while Integer(ContinueLoop) <> 0 do begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
        Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0));
    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;

相关阅读 >>

Delphi 通用压缩单元

Delphi 取得文件夹及下一级文件夹下的文件列表

Delphi 如何从url提取文件名?

Delphi 打开"我的电脑"等特殊文件夹

Delphi中实现hextostr函数和strtohex函数

常用的几个网络函数和系统函数

Delphi firemonkey的屏幕分辨率hdpi、mdpi、ldpi的差别

Delphi 字符串加密与解密函数

Delphi 计算运行耗时的方法1

Delphi禁止webbrowser弹出窗口或者脚本错误

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



打赏

取消

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

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

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

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

评论

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