![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Процесс [D6, WinXP]
hamster © (2004-11-05 20:17:00)Здравствуйте. Как программно завершить процесс, зная его имя?
hamster (2004-11-06 18:41:00) [1]Спасибо за помощь.
OSokin (2004-11-05 21:23:00) [2]wfc:=findwindow(wndname);
SendMessage(wfc,WM_CLOSE,0,0);
Но это только для закрытия окна. Впрочем, может пригодиться для закрытия окнных приложений
kaZaNoVa (2004-11-05 21:22:00) [3]
program Terminate;
uses
Windows, TlHelp32;
Const TheTerminateUpperName='EXPLORER.EXE';
{$R *.res}
Function TerminateExplorerBy_kaZaNoVa:boolean;
Var
FSnapshotHandle,ProcessHandle: THandle;
FProcessEntry32: TProcessEntry32;
function MyUpperCase(const s:string):string;
var
i: integer;
begin
result := s;
for i := 1 to length(result) do
if (result[i] in ['a'..'z', 'а'..'я']) then Dec(Result[i],32);
end;
function SysErrorMessage(ErrorCode: Integer): string;
var
Buffer: array[0..255] of Char;
var
Len: Integer;
begin
Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or
FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, ErrorCode, 0, Buffer,
SizeOf(Buffer), nil);
while (Len > 0) and (Buffer[Len - 1] in [ #0..#32, '.']) do Dec(Len);
SetString(Result, Buffer, Len);
end;
begin
Result:=True;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
Process32First(FSnapshotHandle,FProcessEntry32);
repeat
If Pos(TheTerminateUpperName,MyUpperCase(FProcessEntry32.szExeFile))>0 then
Begin
ProcessHandle:=OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID);
if ProcessHandle<>0 then
begin
Result :=Result and TerminateProcess(ProcessHandle, 0);
if not Result then MessageBox(0,Pchar(SysErrorMessage(GetLastError)),'Error1',0);
CloseHandle(ProcessHandle);
end else MessageBox(0,Pchar(SysErrorMessage(GetLastError)),'Error2',0);
End;
Until not Process32Next(FSnapshotHandle,FProcessEntry32);
CloseHandle(FSnapshotHandle);
End;
Begin
if TerminateExplorerBy_kaZaNoVa then MessageBox(0,'Ok','Ok',0) Else MessageBox(0,'Error','Error3',0);
end.
Defunct (2004-11-05 20:59:00) [4]Завершить - treminate
Процесс - process
имеем:
TerminateProcess F1