unction KillTask(const ExeName: string): Boolean;
{
强制终止ExeName对应的应用程序
}
var
lppe: TProcessEntry32;
SH, PID: THandle;
Found: boolean;
begin
Result := False;
//EnablePrivilege('SeDebugPrivilege', True);
lppe.dwSize := SizeOf(lppe);
SH := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
found := Process32First(SH, lppe);
while found do
begin
if SameText(ExeName, ExtractFileName(lppe.szExeFile)) then
begin
PID := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
Result := TerminateProcess(PID, DWORD(-1));
CloseHandle(PID);
end;
found := Process32Next(SH, lppe);
end;
//EnablePrivilege('SeDebugPrivilege', False);
end;
用如上函数可以结束普通运行的exe文件进程,但是如果是以system运行的,结束不了,求解,改怎么办?
{
强制终止ExeName对应的应用程序
}
var
lppe: TProcessEntry32;
SH, PID: THandle;
Found: boolean;
begin
Result := False;
//EnablePrivilege('SeDebugPrivilege', True);
lppe.dwSize := SizeOf(lppe);
SH := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
found := Process32First(SH, lppe);
while found do
begin
if SameText(ExeName, ExtractFileName(lppe.szExeFile)) then
begin
PID := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
Result := TerminateProcess(PID, DWORD(-1));
CloseHandle(PID);
end;
found := Process32Next(SH, lppe);
end;
//EnablePrivilege('SeDebugPrivilege', False);
end;
用如上函数可以结束普通运行的exe文件进程,但是如果是以system运行的,结束不了,求解,改怎么办?
解决方案 »
- ADO访问Access数据库的问题
- 帮我算算 我得多久才可以升个星啊~
- 数据库按字段提取数据
- 高分相送:怎么设置DBGrid 某一指定单元格的颜色,不是一行是一个单元格的颜色###############################
- socker error #10054 错误怎么解决
- delphi程序里怎么可以检测到手机已经和USB数据线连接上?
- DBGrid焦点的问题
- 为什么LAN中其他机器不能访问我的APPSERVER?
- 想开发一个邮件客户端程序,但delphi 刚入门,所以不知从何做起,特向高手请教!!!
- 在dbgrid中如何显示memo型字段的内容?
- 关于delphi的MD5算法
- 帮忙将下面VB.NET 的代码 转换为delphi
我觉得这里的PROCESS_ALL_ACCESS取得了当前用户对于该程序的权限,而不具有system权限
var
hWndClose :HWnd; //存储指定的外部应用程序窗口句柄
str :string; //存储指定的外部应用程序
begin
str :=exe_name ; //获取要关闭的应用程序
if str <> '' then
begin
//根据窗口名查找要关闭的窗口句柄
hWndClose := FindWindow(nil, PChar(str));
if hWndClose <> 0 then //如果查找成功,则发送消息,关闭指定的窗口
begin
SendMessage(hWndClose, WM_CLOSE, 0, 0);
end;
end;
end;