如何在Windows API中查询驱动器的制造商?

问题描述 投票:0回答:1

我对如何以编程方式检测连接到Windows PC的硬盘驱动器,SSD等的制造商感兴趣。如果有什么不同,我可能会在Windows 10上使用C ++。

也许有多个级别,也许是注册表,Windows API,SATA,USB?

我需要一种适用于通过USB连接的外部驱动器的方法。我想我正在寻找可查询硬件的Windows API。

谷歌搜索,我只能找到从控制台或某些应用程序中查看此信息的方法,或者查询有关驱动器而不是制造商的其他信息的方法。

windows winapi drive usb-drive
1个回答
0
投票

例如,您可以在下面的注册表项中找到硬件磁盘制造商的名称:

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0

似乎有一个值名称“ Identifier”:

enter image description here

以下是使用Registry Functions查询该值的示例:

#include <windows.h>
#include <tchar.h>

#define MAX_VALUE_NAME 16383

void QueryKey(HKEY hKey)
{
    DWORD    cValues;   // number of values for key 
    DWORD    retCode;
    TCHAR    pvData[MAX_VALUE_NAME];
    DWORD    cbData = sizeof(TCHAR) * MAX_VALUE_NAME;
    TCHAR    targetValue[] = L"Identifier";

    // Get the value count. 
    retCode = RegQueryInfoKey(
        hKey,           // key handle 
        NULL,           
        NULL,           
        NULL,                    
        NULL,               
        NULL,            
        NULL,            
        &cValues,       // number of values for this key 
        NULL,            
        NULL,         
        NULL,   
        NULL);       

    // Get the key value. 
    if (cValues)
    {
        retCode = RegGetValue(hKey, NULL, targetValue, RRF_RT_REG_SZ, NULL, pvData, &cbData);
        if (retCode != ERROR_SUCCESS)
        {
            _tprintf(TEXT("RegGetValue fails with error: %d\n", retCode));
            return;
        }
        _tprintf(TEXT("%s: %s\n"), targetValue, pvData);
    }
}

void main(void)
{
    HKEY hTestKey;

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
        TEXT("HARDWARE\\DEVICEMAP\\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0"),
        0,
        KEY_READ,
        &hTestKey) == ERROR_SUCCESS
        )
    {
        QueryKey(hTestKey);
    }

    RegCloseKey(hTestKey);
}
© www.soinside.com 2019 - 2024. All rights reserved.