怎样能算出已打开运行的相同程序的数目?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
      function FindProcess(AFileName: string): Integer;
      var
        hSnapshot: THandle;
        lppe: TProcessEntry32;
        Found: Boolean;
        KillHandle: THandle;
        i:Integer;
      begin
        i:=0;
        hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        lppe.dwSize := SizeOf(TProcessEntry32);
        Found := Process32First(hSnapshot, lppe);
        while Found do
        begin
          if ((UpperCase(ExtractFileName(lppe.szExeFile))=UpperCase(AFileName)) or (UpperCase(lppe.szExeFile )=UpperCase(AFileName))) then
          begin
            Inc(I);
          end;
          Found := Process32Next(hSnapshot, lppe);
        end;
        Result:=I;
      end;
    begin
      showmessage( intToStr( FindProcess('svchost.exe') ) );
    end;
    ---------------------------
    Project1
    ---------------------------
    5
    ---------------------------
    OK   
    ---------------------------