Solved

PHYSICAL DISK SIZE

Posted on 2003-10-21
1
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

631 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