procedure GetVolumeSectorSize(Volume:
string);
function GetWMIObject(
const objectName:
string): IDispatch;
var
chEaten: Integer;
BindCtx: IBindCtx;
// for access to a bind context
Moniker: IMoniker;
// Enables you to use a moniker object
begin
OleCheck(CreateBindCtx(0, BindCtx));
OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));
// Converts a string into a moniker that identifies the object named by the string
OleCheck(Moniker.BindToObject(BindCtx,
nil, IDispatch, Result));
// Binds to the specified object
end;
var
FWMIService, FWMIServiceEx: OLEVariant;
FWbemObjectSet, FWbemObjectSetEx: OLEVariant;
oEnum, oEnumEx: IEnumvariant;
iValue, iValueEx: LongWord;
begin;
Volume := Trim(Volume);
if Volume = '
'
then
Exit;
FWMIService := GetWMIObject(Format('
winmgmts:\\%s\%s', ['
.', '
root\CIMV2']));
FWbemObjectSet := FWMIService.ExecQuery(Format('
SELECT * FROM %s WHERE DriveLetter=%s', ['
Win32_Volume ', QuotedStr(Volume + '
:')]), '
WQL', 0);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumvariant;
if oEnum.Next(1, FWbemObjectSet, iValue) = 0
then
begin
FWMIServiceEx := GetWMIObject(Format('
winmgmts:\\%s\%s', ['
.', '
root\CIMV2']));
FWbemObjectSetEx := FWMIServiceEx.ExecQuery(Format('
SELECT * FROM %s', ['
Win32_DiskDrive']), '
WQL', 0);
oEnumEx := IUnknown(FWbemObjectSetEx._NewEnum)
as IEnumvariant;
while oEnumEx.Next(1, FWbemObjectSetEx, iValueEx) = 0
do
begin
ShowMessage(
string(FWbemObjectSet.Properties_.Item('
DriveLetter', 0)) + sLineBreak +
string(FWbemObjectSetEx.Properties_.Item('
Caption', 0)) + '
: ' + Format('
BytesPerSector %d',
[Integer(FWbemObjectSetEx.Properties_.Item('
BytesPerSector', 0))]));
end;
end;
end;
CoInitialize(
nil);
try
GetVolumeSectorSize('
D');
finally
CoUninitialize;
end;