delphi 定时关闭其他应用程序

来源:百度知道 编辑:UC知道 时间:2024/06/09 04:01:22
我想请教几个问题。我用delphi做了一个链接
procedure TForm1.Button1Click(Sender: TObject);
var
nResult : Integer ;
begin
nResult := WinExec ( 'C:\Program Files\360\360se3\360SE.exe' , 0 ) ;
if nResult > 31 then
ShowMessage ( '浏览器成功运行!' )

我想让浏览器在 空闲 1分钟后强制关闭,应当怎样加入代码?
谢谢

只是让浏览器空闲一分钟这不好编写,如果是让计算机空闲一分钟这还好办.

用进程名返回进程ID函数:
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 TForm1.Button1Click(Sender: TObject);
var
id: Card