我有进程ID,需要用Delphi 5以编程方式关闭关联的进程 [英] I have the Process ID and need to close the associate process programmatically with Delphi 5

查看:136
本文介绍了我有进程ID,需要用Delphi 5以编程方式关闭关联的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我具有流程ID时,谁能帮助我提供一个编码示例来关闭相关的流程。我将使用Delphi 5在Windows 2003服务器上以编程方式执行此操作。

Can anyone help me with a coding example to close the associated process when I have the Process ID. I will be using Delphi 5 to perform this operation programmatically on a Windows 2003 server.

推荐答案

如果您有进程ID并且想要要强制该进程终止,可以使用以下代码:

If you have a process id and want to force that process to terminate, you can use this code:

function TerminateProcessByID(ProcessID: Cardinal): Boolean;
var
  hProcess : THandle;
begin
  Result := False;
  hProcess := OpenProcess(PROCESS_TERMINATE,False,ProcessID);
  if hProcess > 0 then
  try
    Result := Win32Check(Windows.TerminateProcess(hProcess,0));
  finally
    CloseHandle(hProcess);
  end;
end;

这篇关于我有进程ID,需要用Delphi 5以编程方式关闭关联的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆