It can be done by enumerating volumes (IVdsPack::QueryVolumes) and subtracting the volumes sizes (IVdsVolume::GetProperties)
from disk size IVdsDisk::GetProperties
But it is complex (tested on Windows 10 21H1)
How to obtain the value of unallocated space of each hard disk of the computer through the Windows interface?
Now I want to read the value of the unallocated space of each hard disk of the computer through the Windows interface, as shown in the red box in the figure. I tried using WMI, but it doesn't seem like there's any good way to do it right now. (If there is a relevant interface, expect to call it via Python or C#)
Thanks~
2 answers
Sort by: Most helpful
-
Castorix31 86,486 Reputation points
2022-10-28T13:31:29.613+00:00 -
Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
2022-10-31T02:46:56.01+00:00 Another way is using WMI class Win32_DiskDrive, Win32_DiskDriveToDiskPartition to calculate the unallocated space.
For WMI C++ Application Examples, see Example: Getting WMI Data from the Local Computer.
For How to use Win32_DiskDriveToDiskPartition, see How do I detect which drive letter is associated with a logical disk partition?