Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.12.19;
Скачать: CL | DM;

Вниз

Процесс   Найти похожие ветки 

 
hamster ©   (2004-11-05 20:17) [0]

Здравствуйте. Как программно завершить процесс, зная его имя?


 
Defunct ©   (2004-11-05 20:59) [1]

Завершить - treminate
Процесс - process

имеем:
TerminateProcess F1


 
kaZaNoVa ©   (2004-11-05 21:22) [2]

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.


 
OSokin ©   (2004-11-05 21:23) [3]

wfc:=findwindow(wndname);
SendMessage(wfc,WM_CLOSE,0,0);

Но это только для закрытия окна. Впрочем, может пригодиться для закрытия окнных приложений


 
hamster ©   (2004-11-06 18:41) [4]

Спасибо за помощь.



Страницы: 1 вся ветка

Текущий архив: 2004.12.19;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.024 c
8-1095439667
Рыба
2004-09-17 20:47
2004.12.19
ScanLine и RGB


14-1101900365
DelphiN!
2004-12-01 14:26
2004.12.19
Цвет фона ячейки таблицы в HTML


3-1101085149
serko
2004-11-22 03:59
2004.12.19
Установка Ehlib!


14-1101808656
syte_ser78
2004-11-30 12:57
2004.12.19
фельетоны перестроечных времен


4-1099669839
XProger
2004-11-05 18:50
2004.12.19
ClientRect