用Process32first()和Process32Next()
开发人员指南上说得很详细,这两个函数只能在win95\98中使用但上面没有介绍如何获取某一进程所占用的内存大小?

解决方案 »

  1.   

    unit u_CheckProcess; 
    interface 
     
    uses Windows, Classes, PsApi; 
     
    function CheckProcess(aProcessName: string): Boolean;//exename(no path,eg hello.exe) 
    implementation 
     
    function CheckProcess(aProcessName: string): Boolean; 
    type 
      integer = DWORD; // different versions of psapi.pas floating around 
    var 
      i, pidNeeded: Integer; 
      PIDList: array[0..1000] of Integer; // 1000 should be enough 
      PIDName: array[0..MAX_PATH - 1] of char; 
      PH: THandle; 
    begin 
      Result := False; 
      if not Psapi.EnumProcesses(@PIDList, 1000, pidNeeded) then 
      begin 
        Result := False; 
        exit; 
      end; 
      for i := 0 to (pidNeeded div sizeof(Integer) - 1) do 
      begin 
        PH := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, 
          PIDList[i]); 
        if PH <> 0 then 
        begin 
          if psapi.GetModuleBaseName(PH, 0, PIDName, sizeof(PIDName)) > 0 then 
            if aProcessName = pidName then 
            begin 
              Result := True; 
            end; 
          if PH > 0 then 
            CloseHandle(PH); 
        end; 
      end; 
    end; 
    end.