Delphi结束进程模块
uses Tlhelp32;
function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOLean;
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;
调用的时候只需要
if KillTask('qq.exe') <> 0 then
showmessage('结束QQ成功')
else
showmessage('无法结束QQ');
你在程序里面用一个计时器,每隔一秒钟检查一下,如果有就结束,也就实现了禁止运行的目的。
procedure TForm1.Timer1Timer(Sender: TObject);
begin
KillTask('qq.exe');
end;
相关文档:
在Delphi中,通常可以用以下三种方法来实现程序的延时,即TTtimer控件,Sleep函数,GetTickCount函数。但是其精度是各不相同的。
一、三种方法的简单介绍
1)TTtimer控件
TTtimer控件的实质是调用Windows API定时函数SetTimer和KillTimer来实现的,并简化了对WM_TIMER 消息的处理过程。通过设置OnTimer事
件和Inte ......
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Bu ......
朋友,先要导入 XDICTGRB_TLB ,然后用下面的source,注意TForm1 = class(TForm,IXDictGrabSink) //!!!
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, XDICTGRB_TLB;
type
TForm1 = class(TForm,IXDictGrabSink) //!!!
GrabPro ......
implementation
uses ComOBJ;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var ExcelAPP1:Variant;
ExcelApp2:Variant;
I,j: Integer;
ID,IDX:string;
begin
try
ExcelAPP1:=CreateOleObject('Excel.Application');
E ......