获取磁盘转速示例代码

发布于 2024-11-03 15:20:51 字数 117 浏览 5 评论 0原文

我不太擅长 VC++,但是有人有示例代码来获取计算机中磁盘的旋转速度吗?我一直致力于检测 SSD 驱动器,整天研究的一个解决方案是获取旋转速度,由于 SSD 的转速为 0 rpm,这可能是检测 SSD 驱动器的唯一方法。

Im not really good at VC++ but does anyone have a sample code to get the rotation speed of disk in a computer. I have been working on detecting SSD drives and one solution from researching all day was to get the rotation speed and since SSD have 0 rpm this might be the only way to detect SSD drive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青柠芒果 2024-11-10 15:20:51

来自 Google wmi ssd 检测

有一个 NV 缓存管理器接口用于ReadyDrive 这是 Vista 中的新功能。我认为它正在测试 NV_FEATURE_PARAMETER 的 NVReadSpeed 和 NVWrtSpeed 值。

Windows 7 使用 ATA8-ACS 识别字 217 来检测 SSD:标称介质旋转速率,值为 0001h 作为非旋转介质(如固态设备)。但并非所有 SSD 都遵守 ATA8-ACS1 规范第 7.16.7.77 部分,有些可能需要固件更新。

如果您想了解有关在 Windows 中发送 ATA 命令的更多信息,我建议您深入研究存储平台 ATA 论坛。该论坛正在存档,请尽快行动。


也非常有启发性:

http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-qa-for-solid-state-drives-and.aspx

SSD 上会默认禁用磁盘碎片整理吗?

是的。碎片整理的自动调度将排除声明自己为 SSD 的设备上的分区。此外,如果系统磁盘的随机读取性能特征高于 8 MB/秒的阈值,那么它也将被排除。阈值由内部分析确定。

From google wmi ssd detect

There is an NV cache manager interface used for ReadyDrive which is new to Vista. I think it is testing NV_FEATURE_PARAMETER's NVReadSpeed and NVWrtSpeed values.

Windows 7 detects SSDs by using ATA8-ACS identify word 217: Nominal media rotation rate, with value 0001h as Non-rotating media like solid state devices. But not all SSDs adhere to the ATA8-ACS1 spec section 7.16.7.77, some may need firmware updates.

If you want to lean more about sending ATA commands in Windows, I suggest you to dig aound the Storage Platform ATA forum. This forum is being archived so act quickly.


Also very enlightening:

http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx

Will disk defragmentation be disabled by default on SSDs?

Yes. The automatic scheduling of defragmentation will exclude partitions on devices that declare themselves as SSDs. Additionally, if the system disk has random read performance characteristics above the threshold of 8 MB/sec, then it too will be excluded. The threshold was determined by internal analysis.

小瓶盖 2024-11-10 15:20:51

我知道这是一个旧线程,但这适用于 Windows 10

ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk");
            scope.Connect();
            searcher.Scope = scope;
            string type = "";
            foreach (ManagementObject queryObj in searcher.Get())
            {
                switch (Convert.ToInt16(queryObj["MediaType"]))
                {
                    case 1:
                        type = "Unspecified";
                        break;

                    case 3:
                        type = "HDD";
                        break;

                    case 4:
                        type = "SSD";
                        break;

                    case 5:
                        type = "SCM";
                        break;

                    default:
                        type = "Unspecified";
                        break;
                }
            }
            searcher.Dispose();

I know this is an old thread but this will work on Windows 10

ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk");
            scope.Connect();
            searcher.Scope = scope;
            string type = "";
            foreach (ManagementObject queryObj in searcher.Get())
            {
                switch (Convert.ToInt16(queryObj["MediaType"]))
                {
                    case 1:
                        type = "Unspecified";
                        break;

                    case 3:
                        type = "HDD";
                        break;

                    case 4:
                        type = "SSD";
                        break;

                    case 5:
                        type = "SCM";
                        break;

                    default:
                        type = "Unspecified";
                        break;
                }
            }
            searcher.Dispose();
金橙橙 2024-11-10 15:20:51

您最好寻找 TRIM 命令。

BOOL IsDriveSSD(){

    DWORD dwBytesReturned;

    HANDLE volhand = INVALID_HANDLE_VALUE;
    try{
        volhand = CreateFile("\\\\.\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    }
    catch(...){
        volhand = INVALID_HANDLE_VALUE;
    }

    if (volhand == INVALID_HANDLE_VALUE) return FALSE;


    // Test 1: See if we have a TRIM command, if so, we're SSD.
    STORAGE_PROPERTY_QUERY spq;
    DEVICE_TRIM_DESCRIPTOR dtr;
    memset(&dtr,0,sizeof(DEVICE_TRIM_DESCRIPTOR));
    memset(&spq,0,sizeof(STORAGE_PROPERTY_QUERY));
    spq.PropertyId=StorageDeviceTrimProperty;
    spq.QueryType=PropertyStandardQuery;

    BOOL ret = DeviceIoControl(volhand, IOCTL_STORAGE_QUERY_PROPERTY,
        &spq,sizeof(spq),
        &dtr,sizeof(dtr),
        &dwBytesReturned,FALSE);

    if(ret){
        ret = dtr.TrimEnabled;
    }

    CloseHandle(volhand);

    return ret;
}

You are likely better off looking for the TRIM command.

BOOL IsDriveSSD(){

    DWORD dwBytesReturned;

    HANDLE volhand = INVALID_HANDLE_VALUE;
    try{
        volhand = CreateFile("\\\\.\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    }
    catch(...){
        volhand = INVALID_HANDLE_VALUE;
    }

    if (volhand == INVALID_HANDLE_VALUE) return FALSE;


    // Test 1: See if we have a TRIM command, if so, we're SSD.
    STORAGE_PROPERTY_QUERY spq;
    DEVICE_TRIM_DESCRIPTOR dtr;
    memset(&dtr,0,sizeof(DEVICE_TRIM_DESCRIPTOR));
    memset(&spq,0,sizeof(STORAGE_PROPERTY_QUERY));
    spq.PropertyId=StorageDeviceTrimProperty;
    spq.QueryType=PropertyStandardQuery;

    BOOL ret = DeviceIoControl(volhand, IOCTL_STORAGE_QUERY_PROPERTY,
        &spq,sizeof(spq),
        &dtr,sizeof(dtr),
        &dwBytesReturned,FALSE);

    if(ret){
        ret = dtr.TrimEnabled;
    }

    CloseHandle(volhand);

    return ret;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文