반응형



     * 작업관리자에 뜬 프로세스 찾아 죽이기 

       (출처 http://www.delphi3000.com/articles/article_4324.asp?SK=)


     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;



-----------------------------------------------------------------------------------------------------------------


 * 실행파일이 떠있는지 찾아보기

    uses TLHelp32, Windows;


     function Process32List : Boolean ;

     var

          Process32   : TProcessEntry32 ; // Uses TLHelp32

          SHandle     : THandle ; // the handle of the Windows object

          _ProcessA,

          _ProcessB   : Boolean ;

     begin

          _ProcessB   := FALSE ;


          Process32.dwSize := SizeOf(TProcessEntry32) ;

          SHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0) ;


          try

             _ProcessA := Process32First(SHandle, Process32) ;

             while _ProcessA do

             begin

                   if UpperCase(Process32.szExeFile) = 'TEST.EXE' then

                   begin

                      _ProcessB := TRUE ;

                      break ;

                   end ;


                if _ProcessB then break ;

                _ProcessA := Process32Next(SHandle, Process32) ;

             end ;


          except

          end;

      end;

반응형

'program' 카테고리의 다른 글

Delphi XE2 Unit Scope tables  (0) 2014.06.12
[Delphi] Delphi Xe3 + Indy 10  (0) 2014.01.10
[Delphi] Borland Database Engine (error $2501)  (1) 2013.11.27
[Delphi] GifImage 등록  (0) 2013.11.21
[postgreSql]  (0) 2013.11.20

+ Recent posts