我需要获得硬盘序列号才能使用它作为许可软件的关键.
我在这个url中使用了diskid32代码: http://www.winsim.com/diskid32/diskid32.html
它使用DeviceIoControl Win32 API与IOCTL_STORAGE_QUERY_PROPERTY的IO控制代码.
原文链接:https://www.f2er.com/windows/371318.html我在这个url中使用了diskid32代码: http://www.winsim.com/diskid32/diskid32.html
它使用DeviceIoControl Win32 API与IOCTL_STORAGE_QUERY_PROPERTY的IO控制代码.
有效.但是,当我仔细检查打印在HDD本身的实际序列号时,我发现每2个字节的数字被翻转.
一个简单的解决方案可能是简单地翻转字节.它在Windows XP,Vista和7中工作,但在Windows 8中不需要翻转!
我想知道在Windows XP,Vista和7中翻转字节的确切原因,为什么不在Windows 8中翻转.下一个Windows怎么样?
部分代码与轻微更改:
int drive = 0; HANDLE hPhysicalDriveIOCTL = 0; char driveName [256]; sprintf (driveName,"\\\\.\\PhysicalDrive%d",drive); // Windows NT,Windows 2000,Windows XP - admin rights not required hPhysicalDriveIOCTL = CreateFile (driveName,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,NULL); if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE) { _STORAGE_PROPERTY_QUERY query; DWORD cbBytesReturned = 0; char buffer [10000]; memset ((void *) & query,sizeof (query)); query.PropertyId = StorageDeviceProperty; query.QueryType = PropertyStandardQuery; memset (buffer,sizeof (buffer)); if ( DeviceIoControl (hPhysicalDriveIOCTL,IOCTL_STORAGE_QUERY_PROPERTY,& query,sizeof (query),& buffer,sizeof (buffer),& cbBytesReturned,NULL) ) { _STORAGE_DEVICE_DESCRIPTOR * descrip = (_STORAGE_DEVICE_DESCRIPTOR *) & buffer; char serialNumber [1000]; char modelNumber [1000]; char vendorId [1000]; char productRevision [1000]; flipAndCodeBytes (buffer,descrip -> SerialNumberOffset,1,serialNumber ); ... }