procedure Tsyste.procedu(var str:string);       //得到当前的进程名和ID
var FSnap:Thandle;
    PE:TprocessEntry32;
    PPE:PProcessEntry32;
    str:string;
    
begin
  
  if FSnap>0 then closeHandle(FSnap);
    FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  if FSnap=-1 then
    raise Exception.create('Windows发生致命错误即将关闭!');
    PE.dwsize:=sizeof(PE);
    if Process32first(FSnap,PE) then
      repeat
        New(PPE);
        PPE^:=PE;
        str:=PPE.Th32processID
      until Not Process32next(FSnap,PE);
end;
后面的自己加到程序里
var id:int64;
h,a:thandle;
Id:=strtoint64(str);//杀进程
   h:=openprocess(PROCESS_ALL_ACCESS,True,Id);
        getExitCodeProcess(h,a);

解决方案 »

  1.   

    不要乱用啊
    代码如下: (纯 win32 API)
    program window;uses
       windows, Messages, sysutils,TLhelp32;
    const
       appname = 'Porter';
       App1    = 'notepad.exe';
       App2    = 'notepad.exe';
       TimeLen = 10000;var
       Ok : Bool;
       ProcessListHandle : hwnd;
       ProcessStruct : TProcessEntry32;
       amessage : tmsg;
       hwindow : hwnd;
       H : hwnd;
       A : DWORD;function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer;
             stdcall; external 'KERNEL32.DLL';function windowproc(window : hwnd; amessage,wparam,lparam : longint) : longint;stdcall;export;
    begin
       windowproc := 0;   case amessage of
          wm_destroy :
             begin
                killtimer(window,1);
                postquitmessage(0);
                exit;
             end;
          wm_create :
             begin
                SetWindowLong(window,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
                RegisterServiceProcess(GetCurrentProcessID, 1);
                settimer(window,1,TimeLen,nil);
             end;
          wm_timer :
             begin
                ProcessListHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);
                ProcessStruct.dwsize := SizeOf(ProcessStruct);
                Ok := Process32First(ProcessListHandle,ProcessStruct);            while integer(Ok) <> 0 do
                begin
                   if (lowercase(extractfilename(ProcessStruct.szExeFile)))= App1 or
                      (lowercase(extractfilename(ProcessStruct.szExeFile)))= App2
                   then
                   begin
                      H := OpenProcess(PROCESS_ALL_ACCESS,True,ProcessStruct.th32ProcessID);
                      GetExitCodeProcess(H,A);
                      if integer(TerminateProcess(H,A)) <> 0 then
                      begin
                      end;
                   end;
                   Ok := Process32Next(ProcessListHandle,ProcessStruct);
                end;
             end;
       end;   windowproc := defwindowproc(window,amessage,wparam,lparam);
    end;function winregister : boolean;
    var
       windowclass : twndclass;
    begin
       //windowclass.style := cs_redraw or cs_vrdraw;
       windowclass.lpfnwndproc := @windowproc;
       windowclass.cbclsextra := 0;
       windowclass.cbwndextra := 0;
    //   windowclass.histance := hinstance;
       windowclass.hicon := loadicon(0,idi_application);
       windowclass.hcursor := loadcursor(0,idc_arrow);
       windowclass.hbrbackground := hbrush(color_window);
       windowclass.lpszmenuname := nil;
       windowclass.lpszclassname := appname;   result := registerclass(windowclass) <>0;
    end;function wincreate : hwnd;
    var
       hwindow : hwnd;
    begin
       hwindow := createwindow(appname,'Porter',ws_overlappedwindow,cw_usedefault,cw_usedefault,
                  cw_usedefault,cw_usedefault,0,0,hinstance,nil);
       result := hwindow;
    end;//main
    begin
       if not winregister then exit;   hwindow := wincreate;   if hwindow = 0 then exit;   while getmessage(amessage,0,0,0) do
       begin
          translatemessage(amessage);
          dispatchmessage(amessage);
       end;   halt(amessage.wparam);
    end.
      

  2.   

    procedure TForm1.LookupProcess;
    var
    DLLinst:THandle;
    ok:boolean;
    LPPROCESSENTRY32:TPROCESSENTRY32;
    i:integer;
    begin
      ListBox1.Clear;
      DLLinst:=LoadLibrary('KERNEL32.DLL');
      if Dllinst>0 then
      begin
        GetProcAddress(DLLinst,'CreateToolhelp32Snapshot');
        ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
        LPPROCESSENTRY32.dwSize:=Sizeof(LPPROCESSENTRY32);
        ok:=Process32First(ProcessListHandle,LPPROCESSENTRY32);
      end;
      i:=0;
      while ok do
      begin
        ListBox1.Items.Add(Lpprocessentry32.szExeFile);
        ok:=Process32Next(ProcesslistHandle,LPPROCESSENTRY32);
        Process[i]:=OpenProcess(PROCESS_TERMINATE,True,LPPROCESSENTRY32.th32ProcessID);
        i:=i+1;
      end;
      CloseHandle(ProcesslistHandle);
    end;procedure TForm1.BitBtn2Click(Sender: TObject);
    var
    now:integer;
    exitcode:DWord;
    begin
      if Listbox1.ItemIndex<0 then
      ShowMessage('嘿嘿...这也太欺负我们小猪了,总得先选个目标吧!')
      else
      begin
        now:=Listbox1.ItemIndex-1;
        GetExitCodeProcess(Process[now],exitcode);
        if TerminateProcess(Process[now],exitcode) then
        Listbox1.Clear
        else if PostMessage(Process[now],WM_QUIT,0,0) then
        ListBox1.Clear
        else  ShowMessage('呜呜... 俺小猪无能为力了!');  end;end;
      

  3.   

    to: jasonet
       楼上的几位对不对呀????如果对了就赶快加分吧.