使用C#获取硬盘速度

时间:2012-05-18 06:37:54

标签: c#

可以使用C#获取硬盘信息吗?

Like spin rate in RPM
Model Number 
Company Name
Data Transfer Rate
Seek Time

最重要的是旋转速度。

我试过

ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");

属性,但它没有给出旋转速率。

请帮帮我?

  • Dattatrya Moin

2 个答案:

答案 0 :(得分:4)

请检查:Reading ATAPI SMART Data from Drives using .NET; Temperature Anyone?

using System.Management;

public string GetHDDSerial()
{
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

    foreach (ManagementObject wmi_HD in searcher.Get())
    {
        // get the hardware serial no.
        if (wmi_HD["SerialNumber"] != null)
            return wmi_HD["SerialNumber"].ToString();
    }

    return string.Empty;
}

答案 1 :(得分:1)

阅读此Win32_DiskDrive并尝试此操作:

ArrayList hddCollection = new ArrayList();
try
{
    var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
    foreach (ManagementObject wmiObj in searcher.Get)
    {
        HardDrive hdd = new HardDrive();
        hdd.model = wmiObj("Model").ToString;
        hdd.type = wmiObj("InterfaceType").ToString;
        hddCollection.Add(hdd);
        break; // TODO: might not be correct. Was : Exit For
    }
}
catch (Exception ex)
{
    throw ex;
}