Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHYSICAL DISK SIZE

Posted on 2003-10-21
1
Medium Priority
?
365 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 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

782 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