Главная страница
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.026 c
4-1099314757
zsv
2004-11-01 16:12
2004.12.19
реестр


1-1102091894
The Vizit0r!
2004-12-03 19:38
2004.12.19
цикл как процесс


14-1101279635
kot
2004-11-24 10:00
2004.12.19
Freddie Mercury и группа QUEEN


1-1102157928
SMT
2004-12-04 13:58
2004.12.19
Идентификация версии Excel


3-1100789231
turonix
2004-11-18 17:47
2004.12.19
Как послать запрос в DB FireBird используя компонент pFIBQuary?