判断一个应用程序还在运行的语句应该怎么写?谢谢。

解决方案 »

  1.   

    procedure Tfrm_rtu_nwkmain.checkpro;
    var
      ippe:tprocessentry32;
      sshandle:thandle;
      found:boolean;
      ttt : boolean;
    begin
      sshandle:=createtoolhelp32snapshot(TH32CS_SNAPPROCESS,0);
      found:=process32first(sshandle,ippe);
      while found do
      begin
        if ansicomparetext(extractfilename(ippe.szExeFile),'Myexe.exe')=0 then
        begin
          showmessage('fount');
          break;
        end;
        found:=process32next(sshandle,ippe);    sleep(1);
      end;end;
      

  2.   


    if Findwindow(nil,'应用程序标题')<>0 then
       showmessage('程序已运行了');
      

  3.   

    程序运行的时候执行
      CreateMutex(nil,true,sMutexName);
      if GetLastError=ERROR_ALREADY_EXISTS then
        该程序已经运行
      

  4.   

    使用完整路径做比较(搬顶楼的代码):
    uses
        tlhelp32,psapi;
    --------------------------
    var
      ippe:tprocessentry32;
      sshandle:thandle;
      found:boolean;
      ttt : boolean;
      pProcess:THandle;
      hMod:HMODULE;
      buf:array[0..MAX_PATH] of char;
      cbNeeded:DWORD;
      len:Integer;
    begin
      sshandle:=createtoolhelp32snapshot(TH32CS_SNAPPROCESS,0);
      ippe.dwSize:=sizeof(ippe);
      found:=process32first(sshandle,ippe);
      while found do
      begin
        pProcess:=OpenProcess(PROCESS_QUERY_INFORMATION or
            PROCESS_VM_READ,FALSE,ippe.th32ProcessID);
        if pProcess>0 then
        begin
           if( EnumProcessModules( pProcess, @hMod, sizeof( hMod ),
             cbNeeded ) ) then
           begin
              ZeroMemory(@buf,MAX_PATH+1);
              len:=GetModuleFileNameEx(pProcess, hMod,buf,sizeof (buf));
              buf[len]:=#0;
              //if ansicomparetext(extractfilename(ippe.szExeFile),'Myexe.exe')=0 then
              if ansicomparetext(buf,Application.ExeName)=0 then
              begin
                showmessage('fount');
                break;
              end;
           end;
        end;
        found:=process32next(sshandle,ippe);    //sleep(1);
      end;end;
      

  5.   

    只要把Application.ExeName替换成,你自己所要查找的应用程序的完整路径即可。
      

  6.   

    不好意思,这台电脑没有delphi,明天再试试各位大虾的方法,明天结贴。