Solved

PHYSICAL DISK SIZE

Posted on 2003-10-21
1
354 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now