Middleware Testing Tools

Middleware Testing Tools

 

object Form3: TForm3
  Left = 978
  Top = 563
  Width = 376
  Height = 110
  BorderIcons = [biSystemMenu]
  Caption = #27979#35797#24037#20855
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 16
    Width = 72
    Height = 13
    Caption = #23458#25143#31471#25968#37327#65306
  end
  object Label2: TLabel
    Left = 24
    Top = 48
    Width = 48
    Height = 13
    Caption = #31243#24207#21517#65306
  end
  object Edit1: TEdit
    Left = 112
    Top = 13
    Width = 65
    Height = 21
    TabOrder = 0
    Text = '1'
  end
  object Button1: TButton
    Left = 183
    Top = 11
    Width = 75
    Height = 25
    Caption = #24320#21551
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 272
    Top = 11
    Width = 75
    Height = 25
    Caption = #20851#38381#25152#26377
    TabOrder = 2
    OnClick = Button2Click
  end
  object Edit2: TEdit
    Left = 112
    Top = 40
    Width = 121
    Height = 21
    TabOrder = 3
    Text = 'd7client.exe'
  end
end

  

unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants,
  Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, Tlhelp32
  ;

type
  TForm3 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Edit2: TEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

function EndProcess(ExeFileName: string): integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOLean;
  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;

procedure TForm3.Button1Click(Sender: TObject);
var
  i: integer;
  p: PAnsiChar;
begin
  p := PAnsiChar(Edit2.Text);
  for i := 1 to StrToIntDef(Edit1.Text, 0) do
    WinExec(p, SW_NORMAL)
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
  EndProcess(Edit2.Text);
end;

end.

  

Guess you like

Origin www.cnblogs.com/hnxxcxg/p/11280511.html