我感兴趣的是如何以编程方式检测连接到Windows PC的硬盘、SSD等的制造商。如果有什么不同的话,我可能会在Windows10上使用C++。
也许有多个层次,也许是注册表、Windows API、SATA、USB?
我需要一种方法,将工作的外部驱动器通过USB连接。我想我正在寻找一个可以查询硬件的Windows API。
我只能在谷歌中找到从控制台或应用程序中查看这些信息的方法,或者查询有关驱动器的其他信息,但不能查询制造商。
发布于 2020-04-22 10:52:00
例如,您可以在以下注册表项中找到硬件磁盘制造商名称:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0
有一个名为"Identifier“的值似乎就是你要找的:

以下是使用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);
}https://stackoverflow.com/questions/61290249
复制相似问题