Solved

PHYSICAL DISK SIZE

Posted on 2003-10-21
1
355 Views
Last Modified: 2010-04-05
Hello.
How I can obtain PHYSICAL (not logical) disk size on Windows 95/98/ME platform?
Thank you.
0
Comment
Question by:Restlin
1 Comment
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 250 total points
ID: 9597900
Use WMI... Import the C:\Windows\System32\wbem\wbemdisp.TLB type library and you can simply call the WMI methods to get the desired information. This should work on ME but maybe not on all 95/98 systems:

(Simple form with one memo control on it)
unit frmMain;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ActiveX, WbemScripting_TLB;
type
  TForm2 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    function NextItem(var Enum: IEnumVARIANT; const riid: TGUID; out ppObject): Boolean;
    procedure DumpProperties(WBEM_Obj: SWBemObject);
  public
  end;
var Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.DumpProperties(WBEM_Obj: SWBemObject);
var
  Enum: IEnumVARIANT;
  SProp: ISWbemProperty;
  PropName: string;
  PropType: string;
  PropValue: string;
begin
  Memo1.Lines.Add(WBEM_Obj.GetObjectText_(0));
  Memo1.Lines.Add('+ WMI Path: ' + WBEM_Obj.Path_.Path);
  Enum := WBEM_Obj.Properties_._NewEnum as IEnumVariant;
  while NextItem(Enum, SWBemProperty, SProp) do begin
    try
      PropName := SProp.Name;
      PropType := VarTypeAsText(VarType(SProp.Get_Value));
      PropValue := VarToStr(SProp.Get_Value);
      Memo1.Lines.Add(Format('%s [%s] = %s', [PropName, PropType, PropValue]));
    except on E: Exception do Memo1.Lines.Add(Format('%s: %s', [PropName, E.Message]));
    end;
  end;
end;
procedure TForm2.FormCreate(Sender: TObject);
var
  Enum: IEnumVARIANT;
  WBEM_Obj: SWBemObject;
begin
  WBEM_Obj := nil;
  Enum := CoSWbemLocator.Create.ConnectServer('.', 'root\cimv2', '', '', '', '', 0, nil).ExecQuery('Select * from Win32_DiskPartition', 'WQL', wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;
  while NextItem(Enum, SWBemObject, WBEM_Obj) and Assigned(WBEM_Obj) do begin
    DumpProperties(WBEM_Obj);
    Memo1.Lines.Add(StringOfChar('-', 40));
  end;
end;
function TForm2.NextItem(var Enum: IEnumVARIANT; const riid: TGUID; out ppObject): Boolean;
var
  OleProperty: OleVariant;
  NumProp: LongWord;
begin
  try
    Result := Succeeded(Enum.Next(1, OleProperty, NumProp)) and (NumProp > 0) and Succeeded(IDispatch(OleProperty).QueryInterface(riid, ppObject));
  except
    Result := False;
    IUnknown(ppObject) := nil;
  end;
end;
end.

Above code displays partition information. Replace Win32_DiskPartition by Win32_DiskDrive and you get the real physical information of all disks.

I can't test if this code works on a 95/98 system with WMI installed on it but it is the easiest way. If it doesn't work, the only way to get the information would be by using the Windows API and some very complex code with possible several flaws and security risks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question