Solved

PHYSICAL DISK SIZE

Posted on 2003-10-21
1
357 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 119
Working this component WebCopy with proxy, help 3 92
enhance the following code 3 37
Delphi problems to abort a printjob 9 25
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

830 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