Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#6

Re: Totale/ Verfügbaren Ram Größe ermitteln...

  Alt 7. Sep 2008, 08:48
Mit WMI sollte es auch gehen:

Delphi-Quellcode:
function GetWMIstring (wmiHost, wmiClass, wmiProperty : string):string;
var // These are all needed for the WMI querying process
  Locator: ISWbemLocator;
  Services: ISWbemServices;
  SObject: ISWbemObject;
  ObjSet: ISWbemObjectSet;
  SProp: ISWbemProperty;
  Enum: IEnumVariant;
  Value: Cardinal;
  TempObj: OleVariant;
  SN: string;
begin
  try
  Locator := CoSWbemLocator.Create;
   Services := Locator.ConnectServer(wmiHost, 'root\cimv2', '', '', '','', 0, nil);
  ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL',
    wbemFlagReturnImmediately and wbemFlagForwardOnly , nil);
  Enum := (ObjSet._NewEnum) as IEnumVariant;
  while (Enum.Next(1, TempObj, Value) = S_OK) do
  begin
    SObject := IUnknown(tempObj) as ISWBemObject;
    SProp := SObject.Properties_.Item(wmiProperty, 0);
    if VarIsNull(SProp.Get_Value) then
      result := ''
    else
    begin
      SN := SProp.Get_Value;
      result := SN;
    end;
  end;
  except // Trap any exceptions (Not having WMI installed will cause one!)
   on exception do
    result := '';
   end;
end;

function AddThouSeps (const S: string): string;
var LS, L2, I : Integer;
    Temp : string;
begin
    result := S ;
    LS := Length (S);
    if LS <= 3 then exit ;
    L2 := (LS - 1) div 3;
    Temp := '';
    for I := 1 to L2 do
            Temp := ThousandSeparator + Copy (S, LS - 3 * I + 1, 3) + Temp;
    Result := Copy (S, 1, (LS - 1) mod 3 + 1) + Temp;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
MaxProcessMemorySize1,FreePhysicalMemory1,FreeSpaceInPagingFiles1,FreeVirtualMemory1 :string;
begin
  Memo1.clear;
  MaxProcessMemorySize1:= getWMIstring('','Win32_OperatingSystem','MaxProcessMemorySize');
  FreePhysicalMemory1:= getWMIstring('','Win32_OperatingSystem','FreePhysicalMemory');
  FreeSpaceInPagingFiles1:= getWMIstring('','Win32_OperatingSystem','FreeSpaceInPagingFiles');
  FreeVirtualMemory1:= getWMIstring('','Win32_OperatingSystem','FreeVirtualMemory');

  Memo1.lines.add(' MaxProcessMemorySize : '+ AddThouSeps(MaxProcessMemorySize1) + ' kB');
  Memo1.lines.add(' FreePhysicalMemory : '+ AddThouSeps(FreePhysicalMemory1) + ' kB');
  Memo1.lines.add(' FreeSpaceInPagingFiles : '+ AddThouSeps(FreeSpaceInPagingFiles1) + ' kB');
  Memo1.lines.add(' FreeVirtualMemory : '+ AddThouSeps(FreeVirtualMemory1) + ' kB');
end;
  Mit Zitat antworten Zitat