How to get the value of StartingOffset properties in class Win32_DiskPartition

时间:2016-05-17 11:20:26

标签: delphi winapi wmi

I got a message

Method 'StartingOffset' not supported by automation object.

Here is a small part of my code:

colLogicalDisks := objWMIService.ExecQuery('ASSOCIATORS OF {Win32_DiskPartition.DeviceID="'+VarToStr(objPartition.DeviceID)+'"} WHERE AssocClass = Win32_LogicalDiskToPartition');
oEnumLogical  := IUnknown(colLogicalDisks._NewEnum) as IEnumVariant;
    while oEnumLogical.Next(1, objLogicalDisk, iValue) = 0 do
    begin
        ShowMessage(objLogicalDisk.StartingOffset);
        driveletter := string(objLogicalDisk.DeviceID);

        if driveletter = ExtractFileDrive(GetCurrentDir) then
        begin
            SetLength(result, 6);
            result[0] := string(objdiskDrive.DeviceID);
            result[1] := string(objdiskDrive.Model);
            result[2] := string(objdiskDrive.MediaType);
            result[3] := string(ConvertBytes(objdiskDrive.Size));
            result[4] := string(objLogicalDisk.Description);
            result[5] := string(ConvertBytes(objLogicalDisk.Size));
        end;
        objLogicalDisk:=Unassigned;
    end;

Source code from here

1 个答案:

答案 0 :(得分:2)

您的代码失败,因为objLogicalDisk变量将实例保存到Win32_LogicalDisk WMI类,您需要访问Win32_DiskPartition类。此外,您的示例代码不完整,但似乎您正在使用发布的代码here。如果是这种情况,您可以通过StartingOffset变量(objPartition

访问objPartition.StartingOffset媒体资源