我想判断c:\1.exe是否运行了,代码该怎么写啊?

解决方案 »

  1.   

    :)try
      ReName 1.exe 2.exe
      ReName 2.exe 1.exe
      ShowMessage('没运行');
    except
      ShowMessage('运行了');
    end;呵呵,有点搞笑
      

  2.   

    比较理想的方法
    枚举进程,并检查进程的exe路径
      

  3.   

    利用SendMessage(FindWindow(类名,nil), WM_CLOSE, 0 ,0);
      

  4.   

    http://blog.csdn.net/nhczp/archive/2007/01/20/1488518.aspx
      

  5.   

    Program project1 //在DELPHI IDE环境下,因为已有Form1存在,所以会提示程序已运行
      Uses 
      Forms,Windows 
      Var Hwnd:Thandle; 
      Begin 
       Hwnd:=FindWindow(‘TForm1’,‘Form1’); 
       If Hwnd=0 then 
         Begin 
         Application.Initialize; 
         Application.CreateForm(TForm1, Form1); 
         Application.Run; 
         End
         else showmessage('App is running!') ;   
      End; 
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,tlhelp32, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Label1: TLabel;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
      function SQLExist:boolean;implementation{$R *.dfm}
    function SQLExist:boolean;
    var ProcessList:Thandle;
        pe:TPROCESSENTRY32;
      begin
      ProcessList:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      pe.dwSize:=sizeof(TPROCESSENTRY32);
     try
      if process32first(ProcessList,pe) then
       if strcomp(pe.szExeFile,'sqlservr.exe')=0 then
          begin
           sqlexist:=true;
           exit;
          end
        else
          while process32next(processlist,pe) do
           if strcomp(pe.szExeFile,'sqlservr.exe')<>0  then
             sqlexist:=false
           else
             begin
               sqlexist:=true;
               exit;
             end;
      finally
        closehandle(processlist);
      end;
      end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if sqlexist then
      label1.Caption:='SQLServer正在运行.'
    else
       label1.Caption:='SQLServer不在运行!';
    end;end.
      

  7.   

    你可以利用一个线称,先枚举窗口,找到的这个窗口进程的PID是不是你的应用程序的PID,如果是你的线程可以提示找到了,如果不是那么你就可以继续找,一般情况下,这样的双重定位会比较保险。