各位老大,怎么关闭一个进程呀,比如QQ,能贴一下原码吗,谢谢。
解决方案 »
- select serverproperty('servername') 怎样在程序中赋给adoquery1
- Delphi中Hook的一个简单问题
- DSPack做视频播放器时的一个问题。
- TDBChart组件在哪里啊?我没找到
- 我想在数据库里存放图标,用listview读取!请问应该怎么做!
- delphi里有显示“确定”和“取消”这两种选择按钮的对话框吗?兄弟们,帮帮忙,在线等,急啊!!解决马上结帐!
- ReportMachine导出excel的问题
- 如何得到GIF每一帧的透明色!
- 请问这样的判卷系统用多线程开发能有效提高效率吗?
- 局域网上的视频文件的播放,高分求解?
- opendialog问题请教
- 如何得到外网ip地址
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapShotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
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(AFileName))
or (UpperCase(FProcessEntry32.szExeFile ) =
UpperCase(AFileName))) then
TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0);
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;
備注AFileName是進程中的名字,如WinWord.exe, calc.exe............
Tlhelp32; function KillTask(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; procedure TForm1.Button1Click(Sender: TObject);
begin
KillTask('notepad.exe');
end; { For Windows NT/2000/XP } procedure KillProcess(hWindowHandle: HWND);
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult); if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0); { Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
end;
var
Exehandle: THandle;
s : String;
begin
s := Listview1.Selected.Caption;
with ListView1 do begin
Exehandle:= OpenProcess(1,BOOL(0),StrToInt(s));
TerminateProcess(Exehandle,0);
ItemFocused.Delete;
end;
end;