如何获得硬盘传输模式?

How to get hdd transfer mode?

我需要获取硬盘传输模式(dma或pio)并打印,你可以在设备管理器中找到它(屏幕截图中的红色圆圈)。

所以我需要从程序中获取红色圆圈中的信息。我试过使用 wmi 类,但是 Win32_DiskDrive、Win32_IDEController 和其他人没有提供我需要的信息。设备管理器中最接近 属性 window 的是 Win32_IDEController,字段 Win32_IDEController["Name"] returns 字符串 ATA Channel 1.

我也找到了这个 https://msdn.microsoft.com/en-us/library/windows/hardware/ff550142(v=vs.85).aspx ,但是它使用 irb.h,那是 ddk(wdk) 的一部分,我以前从未使用过它,所以我什至不知道如何使用这个功能。

现在我正在学习 WDK)任何语言的任何解决方案都很好,在我使用 C# 的项目中,但如果解决方案将使用另一种语言,我可以编写 "DMA" 或 "PIO" 添加到此解决方案中的文件中,从 C# 中执行 .exe 并从文件中读取。 C#中的OFC解决方案将受到更多赞赏。

您可以使用 autoit (https://www.autoitscript.com) 直接从 GUI 读取它。

示例(注意不同的 Windows 版本和不同的语言):

    Run ("mmc c:\windows\system32\devmgmt.msc") 
    WinWaitActive ( "Device Manager" ) 
    send("{tab}{down}{down}{down}{down}{down}{down}{down}{NUMPADADD}{down}!{enter}") 
    WinWaitActive ( "Primary IDE Channel Properties" ) 
    send("^{tab}") 
    $drivemode = ControlGetText("Primary IDE Channel Properties", "", "Static4") 
    ControlClick("Primary IDE Channel Properties","Cancel","Button6") 
    WinKill ( "Device Manager" ) 

如果您想在 C# 中使用 Autoit:

https://www.autoitscript.com/forum/topic/177167-using-autoitx-from-c-net/

您可以使用 STORAGE_ADAPTER_DESCRIPTOR 结构中的 AdapterUsesPio 成员。这是一个 C++ 示例,演示了如何为它查询磁盘:

#include "stdafx.h"

int main()
{
    wchar_t path[1024];
    wsprintf(path, L"\\?\C:"); // or L"\\.\PhysicalDrive0"

    // note we use 0, not GENERIC_READ to avoid the need for admin rights
    // 0 is ok if you only need to query for characteristics
    HANDLE device = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
    if (device == INVALID_HANDLE_VALUE)
        return 0;

    STORAGE_PROPERTY_QUERY query = {};
    query.PropertyId = StorageAdapterProperty;
    query.QueryType = PropertyStandardQuery;

    STORAGE_ADAPTER_DESCRIPTOR descriptor = {};

    DWORD read;
    if (!DeviceIoControl(device, IOCTL_STORAGE_QUERY_PROPERTY,
        &query,
        sizeof(query),
        &descriptor,
        sizeof(descriptor),
        &read,
        NULL
        ))
    {
        wprintf(L"DeviceIoControl error: %i\n", GetLastError());
    }
    else
    {
        wprintf(L"AdapterUsesPio: %i\n", descriptor.AdapterUsesPio);
    }

    CloseHandle(device);
    return 0;
}