比如我有A.exe
运行后,PID为123然后我不关程序,直接再运行过A.exe时,就把PID为123的那个A.exe杀掉..

解决方案 »

  1.   

    没有直接的方法吧
    那你自己就写方法,先扫描当前进程,发现有同名的进程,然后还和自己的进程PID不一样,就关闭掉
    我觉得好麻烦,还不如让程序自己本身关掉好
      

  2.   

    进程PID是无法固定的,不能根据PID来杀,下例根据窗口标题来杀dpr文件program Project1;uses
      Forms,
      windows,
      messages,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    var
      hwndclose:hwnd;
    begin
      hWndClose:=FindWindow(nil, PChar('form1'));//根据A.exe的窗口标题来判断,也可以根据窗口类
      if hwndclose<>0 then
      SendMessage(hWndClose,WM_CLOSE,0,0);
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
      

  3.   

    分数少你也不能胡嘞嘞啊  hWndClose:=FindWindow(nil, PChar('form1'));//根据A.exe的窗口标题来判断,也可以根据窗口类
      if hwndclose<>0 then
      SendMessage(hWndClose,WM_CLOSE,0,0);
    这两句是在程序初始化最早执行的,那时本程序的窗体还没创建呢,没看到Application.CreateForm(TForm1, Form1);在下面吗如果楼主测试成功的话把分给子渊吧 我还有事哩,急着去淘水,把6楼的浅海小鱼干死 哇哈哈哈哈
      

  4.   

    那你人品就更不行了,不想给分就直说嘛  没测试就说我的代码不行 真tymw(五笔)蛋
      

  5.   


    var
      WM_CLOSEWND:UINT;   procedure TfrmMain.TntFormCreate(Sender: TObject);
    begin
      WM_CLOSEWND:=RegisterWindowMessage('WMCLOSEWND');
    end;procedure TfrmMain.WndProc(var Msg: Tmessage);
    var
      username:String;
      iLen:integer;
      pe:PEmployee;
      iniFile:TIniFile;
    begin
      if Msg.Msg = WM_CLOSEWND then begin
        //在这里处理自己的消息事件
      end else
        inherited;
    end;