C++读取硬盘物理序列号-非管理员权限
2021-01-19 20:12
标签:share val amp ati dash csdn rop sha product #include "stdafx.h" C++读取硬盘物理序列号-非管理员权限 标签:share val amp ati dash csdn rop sha product 原文地址:https://www.cnblogs.com/yuanscn/p/12905847.html
#include
#include
int main()
{
static BYTE buffer[0x1000];
WCHAR path[] = L"\\\\.\\PhysicalDrive0";
STORAGE_DEVICE_DESCRIPTOR* descriptor = (STORAGE_DEVICE_DESCRIPTOR*)buffer;
STORAGE_PROPERTY_QUERY p = { StorageDeviceProperty, PropertyStandardQuery };
DWORD retn;
DWORD len = wcslen(path);
while(true) {
HANDLE hDisk = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
if (hDisk == INVALID_HANDLE_VALUE) break;
if (!DeviceIoControl(hDisk, IOCTL_STORAGE_QUERY_PROPERTY, &p, sizeof(p),
buffer, sizeof(buffer), &retn, 0)) break;
wprintf(L"%s\n", path);
if (descriptor->VendorIdOffset > 0)
printf("VendorId: %s\n", buffer + descriptor->VendorIdOffset);
if (descriptor->ProductIdOffset > 0)
printf("ProductId: %s\n", buffer + descriptor->ProductIdOffset);
if (descriptor->ProductRevisionOffset > 0)
printf("ProductRevision: %s\n", buffer + descriptor->ProductRevisionOffset);
if (descriptor->SerialNumberOffset > 0)
printf("SerialNumber: %s\n", buffer + descriptor->SerialNumberOffset);
printf("\n");
CloseHandle(hDisk);
path[len - 1]++;
}
return 0;
}
————————————————
版权声明:本文为CSDN博主「wuxq」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wuxq/java/article/details/89071444
上一篇:c 语言使用lttng
下一篇:Go语言 流程控制
文章标题:C++读取硬盘物理序列号-非管理员权限
文章链接:http://soscw.com/index.php/essay/44206.html