已经知道dos程序的文件名,怎么终止这个进程

解决方案 »

  1.   

    根据程序名称找到 pid 
    ntsd -c q -p pid
      

  2.   

    列举所有进程,判断进程的szExeFile是否等于已知的dos程序名,终止这个进程.
      

  3.   

    uses TlHelp32;
    ...procedure TForm1.Button1Click(Sender: TObject);
    var
      ContinueLoop: BOOLean;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
      ProList:TStringList;
      i:integer;
    begin
      inherited;
      FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
      ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
      ProList := TStringList.Create ;
      try
        while Integer(ContinueLoop) <> 0 do
        begin
          //加入stirnglist
          ProList.Add(FProcessEntry32.szExeFile);
          ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
        end;
        CloseHandle(FSnapshotHandle);
        ShowMessage(ProList.Text );
      finally
        ProList.Free;
      end;
    end;