Windows的哪些版本是Storage Management API类,例如' MSFT_PhysicalDisk'实施?

时间:2017-05-31 00:46:52

标签: c# windows wmi

我正在尝试提取指标,例如' MediaType'来自MSFT_PhysicalDisk。我在Windows 10机器上取得了成功,但在Windows 7机器上却没有。

MSFT_PhysicalDisk可用的机器类型是什么?

Storage Management API类的参考: https://msdn.microsoft.com/en-us/library/windows/desktop/hh830612(v=vs.85).aspx

请参阅下面的代码,了解我尝试做的事情            bool isSsd;             尝试             {                 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;`

1 个答案:

答案 0 :(得分:2)

MSDN文档在页面底部列出了 way 的要求。对于MSFT_PhysicalDisk class,它说......

  

受支持的最低客户端:Windows 8 [仅限桌面应用]

     

受支持的最低服务器:Windows Server 2012 [仅限桌面应用]

换句话说,您至少需要Windows version 6.2