就像任务管理器那样,只需要知道进程名立即可终止。

解决方案 »

  1.   

    TerminateProcessThe TerminateProcess function terminates the specified process and all of its threads.
    BOOL TerminateProcess(
      HANDLE hProcess,
      UINT uExitCode
    );Parameters
    hProcess 
    [in] Handle to the process to terminate. 
    The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights.uExitCode 
    [in] Exit code to be used by the process and threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.
      

  2.   

    给你个代码,可不是我写的哦
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, TLHelp32, Controls, Forms, Dialogs,
      StdCtrls;type
      TProcessInfo = record
        ExeFile: string;
        ProcessId: DWORD;
      end;
      ProcessInfo = ^TProcessInfo;
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure ProcessList(var pList: TList);
        procedure My_RunFileScan(ListboxRunFile: TListBox);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        Current: TList;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ProcessList(var pList: TList);
    var
      p: ProcessInfo;
      ok: Bool;
      ProcessListHandle: THandle;
      ProcessStruct: TProcessEntry32;
    begin
      PList := TList.Create;
      PList.Clear;
      ProcessListHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      ProcessStruct.dwSize := Sizeof(ProcessStruct);
      ok := Process32First(ProcessListHandle, ProcessStruct);
      while Integer(ok) <> 0 do
        begin
          new(p);
          p.ExeFile := ProcessStruct.szExeFile;
          p.ProcessID := ProcessStruct.th32ProcessID;
          PList.Add(p);
          ok := Process32Next(ProcessListHandle, ProcessStruct);
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      h: THandle;
      a: DWORD;
      p: PRocessInfo;
    begin
      if ListBox1.ItemIndex >= 0 then
        begin
          p := Current.Items[ListBox1.ItemIndex];
          h := openProcess(Process_All_Access, true, p.ProcessID);
          GetExitCodeProcess(h, a);      if Integer(TerminateProcess(h, a)) <> 0 then
            begin
              My_RunFileScan(ListBox1);
            end;
        end
      else
        Application.MessageBox('请先选择一个进程!', '黑洞', MB_ICONERROR + MB_OK);
    end;procedure TForm1.My_RunFileScan(ListboxRunFile: TListBox);
    var
      i: Integer;
      p: PRocessInfo;
    begin
      current := TList.Create;
      Current.Clear;
      ListboxRunFile.Clear;
      ProcessList(Current);
      for i := 0 to Current.Count - 1 do
        begin
          new(p);
          p := Current.Items[i];
          ListboxRunFile.Items.Add(p.ExeFile);
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      My_RunFileScan(ListBox1);
    end;end.
      

  3.   

    theone_jxm()的方法只获得了进程文件位置,不是进程名啊?
      

  4.   

    theone_jxm()
    的方法没有把进程关掉,反而把EXPLORER关掉了,只得重启:~~(
      

  5.   

    下面两个函数是一个木马程序里面的两个函数,第一个是取得所有进程,第二个是杀掉进程
    其中第一个过程中的Sendtaskname是进程名,他的值可以作为第二个过程的参数procedure tform1.getclienttask(); //取得客户端的所有进程
    const
      PROCESS_TERMINATE=$0001;
      //进程的PROCESS_TERMINATE访问权限
    var
      SendCode:array[0..250] of char;
      SendCodeStr:string;
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      FSnapshotHandle := CreateToolhelp32Snapshot
                         (TH32CS_SNAPPROCESS, 0);
     //获取系统所有进程快照
      FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
      //调用Process32First前用Sizeof(FProcessEntry32)填充FProcessEntry32.dwSize
      ContinueLoop := Process32First(FSnapshotHandle,
                                     FProcessEntry32);
     //获取快照中第一个进程信息并保存到FProcessEntry32结构体中
      while integer(ContinueLoop) <> 0 do
        begin
           Sendtaskname:=ExtractFileName(FProcessEntry32.szExeFile);
              begin
                   sendCodeStr:='task'+sendtaskname;
                   StrpCopy(sendCode,sendCodeStr);
                   cUDP.RemoteHost:='192.168.0.4';
                   cUDP.SendBuffer(sendCode,250);
              end;
           ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
        end;
    end;function tform1.KillTask(ExeFileName: string): integer;
    const
      PROCESS_TERMINATE=$0001;
      //进程的PROCESS_TERMINATE访问权限
    var
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      result:= 0;
      FSnapshotHandle := CreateToolhelp32Snapshot
                         (TH32CS_SNAPPROCESS, 0);
     //获取系统所有进程快照
      FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
      //调用Process32First前用Sizeof(FProcessEntry32)填充FProcessEntry32.dwSize
      ContinueLoop := Process32First(FSnapshotHandle,
                                     FProcessEntry32);
     //获取快照中第一个进程信息并保存到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;
    end;
      

  6.   

    第一个过程中去掉udp相关部分就可以变成在本机使用的代码,还有不明白的给我发消息
      

  7.   

    我是说,显示出来的进程名。
    ExtractFileName出来的是EXE的文件名,而我需要的是进程名。例如,一个aa.exe的程序在任务管理器里显示的可能bb,而它的主窗体名却是CC。
      

  8.   

    呵呵,aa.exe在任务管理器里面就是aa.exe吧至于主窗体名,指的是主窗体的Caption吗?如果该程序没有主窗体怎么办?或者比如word,主窗体的名字是随着打开的文件变化的?
      

  9.   

    呵呵 貌似TerminateProcess结束不了系统保护的进程,我也不知道什么原因,可能是权限不够还是什么的吧,反正我写了个结束进程的小程序去结束QQ.exe和结束记事本的进程可以正常结束,但是结束360rp.exe却无法结束掉了。以下是我的代码:dll部分:
    uses
      ShareMem,SysUtils,TLHelp32,windows,
      Classes;{$R *.res}function zhaodaojincheng(shuru : string):longword; stdcall;var
      jubing : longword;//进程快照句柄
      fprocessentry32 : TProcessEntry32;//结构类型的变量
      zhenjia : Boolean; //返回一个布尔值
      processid : longword;//储存进程ID
      mingcheng : String;//储存进程名称
      pid : longword;//用来储存进程id
      jinchengjubing : longword; //用来储存进程句柄
      begin
          jubing := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //获得进程快照句柄
          fprocessentry32.dwSize := sizeof(fprocessentry32); //给TProcessEntry32结构的第一个参数赋值(也可以理解为把这个结构的第一个参数初始化)
          zhenjia := Process32First(jubing,fprocessentry32);//取得第一个进程信息
             while zhenjia = true do
                   begin
                    zhenjia := Process32Next(jubing,FprocessEntry32);//取得第下一个进程信息
                    mingcheng := fprocessentry32.szExeFile;//取得一个进程的名称                 if mingcheng = shuru then//如果进程名等于这个字符串
                     pid := fprocessentry32.th32ProcessID;//找到想要的进程的pid
                     jinchengjubing := OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID); //找到进程句柄并打开
                      terminateprocess(jinchengjubing,0); //关闭进程句柄
                     result := pid; //该函数返回值                  end;
                      closehandle(jubing); //释放进程快照的句柄归还系统资源
      end;  exports
      zhaodaojincheng;
    exe部分:implementationfunction zhaodaojincheng(shuru : string):longword;stdcall;external'jinchengdll.dll';procedure TForm1.Timer1Timer(Sender: TObject);
    var
    shuru : string;//给自定义函数输入参数用的变量
    fanhuizhi : longword;begin   shuru := edit1.text; //把进程名存进变量shuru里作为dll里的参数使用
       fanhuizhi := zhaodaojincheng(shuru);//调用dll里的函数end;
    procedure TForm1.Button1Click(Sender: TObject);begin
    timer1.Enabled := true;end;