Gordon Slysz
Gordon Slysz

Reputation: 1143

In what versions of Windows are Storage Management API Classes such as 'MSFT_PhysicalDisk' implemented?

I am trying pull metrics such as 'MediaType' from MSFT_PhysicalDisk. I'm successful on a Windows 10 machine, but not on a Windows 7 machine.

On what type of machines is MSFT_PhysicalDisk available?

The reference for Storage Management API Classes: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/stormgmt/storage-management-api-classes

See code below for an example of what I'm trying to do:

bool isSsd;
try
{
    var physDiskQuery =
        $"SELECT MediaType FROM MSFT_PhysicalDisk WHERE DeviceID='{driveNumber.Value}'";

    var wmiScope = @"\\.\root\microsoft\windows\storage";
    using (var physicalDiskSearcher = new ManagementObjectSearcher(wmiScope, physDiskQuery))
    {
        var objectCollection = physicalDiskSearcher.Get();
        var physicalDisk = objectCollection.Cast<ManagementBaseObject>().SingleOrDefault();
        if (physicalDisk == null)
            return null;

        isSsd = (ushort)physicalDisk["MediaType"] == 4;
    }
}
catch (Exception exception)
{
    Debug.WriteLine($"Error while checking for SSD drive. Details: {exception.GetBaseException()}");
    return null;
}

return isSsd;

Upvotes: 0

Views: 1219

Answers (1)

Lance U. Matthews
Lance U. Matthews

Reputation: 16606

MSDN documentation lists requirements way at the bottom of the page. For the MSFT_PhysicalDisk class it says...

Minimum supported client: Windows 8 [desktop apps only]

Minimum supported server: Windows Server 2012 [desktop apps only]

In other words, you need at least Windows version 6.2.

Upvotes: 2

Related Questions