在 Vista Ultimate 64 位上获取 HDD(而不是卷)序列号
我曾经想在不使用 WMI 的情况下获取 HDD 序列号,我找到了。 我在 StackOverFlow.com 上找到并发布的代码在 32 位 Windows(XP 和 Vista)上运行良好。 当我尝试在 64 位操作系统(特别是 Vista Ultimate 64)上获取序列号时,问题才开始出现。 该代码始终返回 String.Empty 或 Space。
有人知道如何解决这个问题吗?
编辑:
我使用了 Dave Cluderay 建议的工具,得到了有趣的结果:
这是 DiskId32 在 Windows XP SP2 32 位上的输出:
To get all details use "diskid32 /d"
Trying to read the drive IDs using physical access with admin rights
Drive 0 - Primary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Trying to read the drive IDs using the SCSI back door
Drive 4 - Tertiary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Trying to read the drive IDs using physical access with zero rights
**** STORAGE_DEVICE_DESCRIPTOR for drive 0 ****
Vendor Id = []
Product Id = [MAXTOR STM3160215AS]
Product Revision = [3.AAD]
Serial Number = []
**** DISK_GEOMETRY_EX for drive 0 ****
Disk is fixed
DiskSize = 160041885696
Trying to read the drive IDs using Smart
Drive 0 - Primary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Hard Drive Serial Number__________: 6RA26XK3
Hard Drive Model Number___________: MAXTOR STM3160215AS
DiskId32 在 Windows Vista Ultimate 64 位上运行:
To get all details use "diskid32 /d"
Trying to read the drive IDs using physical access with admin rights
Trying to read the drive IDs using the SCSI back door
Trying to read the drive IDs using physical access with zero rights
**** STORAGE_DEVICE_DESCRIPTOR for drive 0 ****
Vendor Id = [MAXTOR S]
Product Id = [TM3160215AS]
Product Revision = [3.AA]
Serial Number = []
**** DISK_GEOMETRY_EX for drive 0 ****
Disk is fixed
DiskSize = 160041885696
Trying to read the drive IDs using Smart
Hard Drive Serial Number__________:
Hard Drive Model Number___________:
请注意 Vista 上的信息要少得多,以及如何不返回序列号。 另外,另一个工具 EnumDisk 将 Vista 上的硬盘称为“SCSI”,而不是 Windows XP 上的“ATA”。
有任何想法吗?
编辑 2:
我发布了 EnumDisks 的结果:
在 Windows XP SP2 32 位上:
Properties for Device 1
Device ID: IDE\DiskMAXTOR_STM3160215AS_____________________3.AAD___
Adapter Properties
------------------
Bus Type : ATA
Max. Tr. Length: 0x20000
Max. Phy. Pages: 0xffffffff
Alignment Mask : 0x1
Device Properties
-----------------
Device Type : Direct Access Device (0x0)
Removable Media : No
Product ID : MAXTOR STM3160215AS
Product Revision: 3.AAD
Inquiry Data from Pass Through
------------------------------
Device Type: Direct Access Device (0x0)
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Rev: 3.AA
Vendor Str :
*** End of Device List ***
以及在 Vista 64 Ultimate 上:
Properties for Device 1
Device ID: SCSI\DiskMAXTOR_STM3160215AS_____3.AA
Adapter Properties
------------------
Bus Type : FIBRE
Max. Tr. Length: 0x20000
Max. Phy. Pages: 0x11
Alignment Mask : 0x0
Device Properties
-----------------
Device Type : Direct Access Device (0x0)
Removable Media : No
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Revision: 3.AA
Inquiry Data from Pass Through
------------------------------
Device Type: Direct Access Device (0x0)
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Rev: 3.AA
Vendor Str :
*** End of Device List ***
I was once looking for getting the HDD serial number without using WMI, and I found it. The code I found and posted on StackOverFlow.com works very well on 32 bit Windows, both XP and Vista. The trouble only begins when I try to get the serial number on 64 bit OSs (Vista Ultimate 64, specifically). The code returns String.Empty, or a Space all the time.
Anyone got an idea how to fix this?
EDIT:
I used the tools Dave Cluderay suggested, with interesting results:
Here is the output from DiskId32, on Windows XP SP2 32-bit:
To get all details use "diskid32 /d"
Trying to read the drive IDs using physical access with admin rights
Drive 0 - Primary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Trying to read the drive IDs using the SCSI back door
Drive 4 - Tertiary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Trying to read the drive IDs using physical access with zero rights
**** STORAGE_DEVICE_DESCRIPTOR for drive 0 ****
Vendor Id = []
Product Id = [MAXTOR STM3160215AS]
Product Revision = [3.AAD]
Serial Number = []
**** DISK_GEOMETRY_EX for drive 0 ****
Disk is fixed
DiskSize = 160041885696
Trying to read the drive IDs using Smart
Drive 0 - Primary Controller - - Master drive
Drive Model Number________________: [MAXTOR STM3160215AS]
Drive Serial Number_______________: [ 6RA26XK3]
Drive Controller Revision Number__: [3.AAD]
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 160041885696 bytes
Hard Drive Serial Number__________: 6RA26XK3
Hard Drive Model Number___________: MAXTOR STM3160215AS
And DiskId32 run on Windows Vista Ultimate 64-bit:
To get all details use "diskid32 /d"
Trying to read the drive IDs using physical access with admin rights
Trying to read the drive IDs using the SCSI back door
Trying to read the drive IDs using physical access with zero rights
**** STORAGE_DEVICE_DESCRIPTOR for drive 0 ****
Vendor Id = [MAXTOR S]
Product Id = [TM3160215AS]
Product Revision = [3.AA]
Serial Number = []
**** DISK_GEOMETRY_EX for drive 0 ****
Disk is fixed
DiskSize = 160041885696
Trying to read the drive IDs using Smart
Hard Drive Serial Number__________:
Hard Drive Model Number___________:
Notice how much lesser the information is on Vista, and how the Serial Number is not returned. Also the other tool, EnumDisk, refers to my hard disks on Vista as "SCSI" as opposed to "ATA" on Windows XP.
Any ideas?
EDIT 2:
I'm posting the results from EnumDisks:
On Windows XP SP2 32-bit:
Properties for Device 1
Device ID: IDE\DiskMAXTOR_STM3160215AS_____________________3.AAD___
Adapter Properties
------------------
Bus Type : ATA
Max. Tr. Length: 0x20000
Max. Phy. Pages: 0xffffffff
Alignment Mask : 0x1
Device Properties
-----------------
Device Type : Direct Access Device (0x0)
Removable Media : No
Product ID : MAXTOR STM3160215AS
Product Revision: 3.AAD
Inquiry Data from Pass Through
------------------------------
Device Type: Direct Access Device (0x0)
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Rev: 3.AA
Vendor Str :
*** End of Device List ***
And on Vista 64 Ultimate:
Properties for Device 1
Device ID: SCSI\DiskMAXTOR_STM3160215AS_____3.AA
Adapter Properties
------------------
Bus Type : FIBRE
Max. Tr. Length: 0x20000
Max. Phy. Pages: 0x11
Alignment Mask : 0x0
Device Properties
-----------------
Device Type : Direct Access Device (0x0)
Removable Media : No
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Revision: 3.AA
Inquiry Data from Pass Through
------------------------------
Device Type: Direct Access Device (0x0)
Vendor ID : MAXTOR S
Product ID : TM3160215AS
Product Rev: 3.AA
Vendor Str :
*** End of Device List ***
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您需要确保您的 P/Invoke 定义是 64 位友好的。 或者,尝试将解决方案中项目的目标 CPU 设置为 32 位。 有关 P/Invoke 和 64 位的更多信息,请访问此处 。
编辑:
以下重写的代码可能更适合您 - 基本上我已经整理了 P/Invoke 定义并添加了更好的错误处理。 该代码两次尝试获取序列号。 第一个使用
IOCTL_STORAGE_QUERY_PROPERTY
,第二个使用SMART_RCV_DRIVE_DATA
。这是调用它的代码:
我只有一台 64 位机器来测试,但这段代码确实可以在它上运行。
You need to ensure that your P/Invoke definitions are 64-bit friendly. Alternatively, try setting the target CPU of the projects in your solution to 32-bit. More information on P/Invoke and 64-bit can be found here.
EDIT:
The following rewritten code might work better for you - basically I've tidied up the P/Invoke definitions and added better error handling. The code makes two attempts to obtain the serial number. The first uses
IOCTL_STORAGE_QUERY_PROPERTY
and the second usesSMART_RCV_DRIVE_DATA
.This is the code to call it:
I only have one 64-bit machine to test against, but this code does work on it.
此代码应该为您提供硬盘序列号。 它与您链接到的代码类似 (
ReadPhysicalDriveInNTWithAdminRights
),但具有几个附加功能。This code should give you the hard disk serial number. It's similar (
ReadPhysicalDriveInNTWithAdminRights
) to your code you linked to but with several additional functions.在 Windows 7 64 上工作:
Win32_PhysicalMedia 类可能不在 64 位平台上提供。
即使 Disk32 此时也可以工作(除了翻转序列号字节时的错误),因为它基于相同的概念。
Got working on Windows 7 64:
Probably the class Win32_PhysicalMedia is not served on 64 bit platforms.
Even Disk32, at this time, is working (apart a bug when flipping serial number bytes), because is based on the same concepts.
修改自代码此处< /a>:
在运行 Vista Home Premium x64 的系统上,给我一个 40 个字符的十六进制字符串,我假设它是我的序列号。 我稍后会打开盒子并确认,但请尝试一下,看看它是否是您想要的。
Modified from the code here:
On my system running Vista Home Premium x64, gives me a 40-character hex string that I'm assuming is my serial number. I'll open up the box and confirm later, but give that a try and see if it's what you're looking for.
您可能希望使用 Windows 非托管 API 来执行此操作:使用
正确的结构调用 GetVolumeInformation api 并查找VolumeSerialNumber 整数字段。
这个 API 已经存在很长时间了,并且从 Windows 98 开始就为我工作。不幸的是,无法在 x64 上检查它。
您可以使用其他 Windows 工具查看正确的序列号吗?
顺便说一句:“0”是有效的序列号! 如果从备份或类似内容恢复磁盘映像,则可能会发生这种情况。
You might want to use Windows unmanaged API to do this:
call GetVolumeInformation api with proper struct and find VolumeSerialNumber integer field.
This API is there for ages and was working for me since Windows 98. Unfortunately, can't check it on x64.
Can you see the correct serial number using other Windows tools?
By the way: '0' is a valid serial number! This might happen if disk image was restored from backup or something like that.
此代码会尝试三次获取序列号:
IOCTL_STORAGE_QUERY_PROPERTY
。SMART_RCV_DRIVE_DATA
。此代码适用于 64 位:
这是调用它的代码:
编辑 - 我更改了主要方法来显示每次尝试比较的结果。 这有望说明这些技术是如何成功和失败的。
This code makes three attempts at obtaining the serial number:
IOCTL_STORAGE_QUERY_PROPERTY
.SMART_RCV_DRIVE_DATA
.IOCTL_SCSI_PASS_THROUGH
.This code works for me on 64-bit:
And here's the code to call it:
EDIT - I've changed the main method to display the results of each attempt for comparison. This will hopefully illustrate how hit and miss these techniques can be.
将 DeviceIoControl 与 IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER 一起使用
或检查 IOCTL_CHANGER_GET_PRODUCT_DATA
use DeviceIoControl with IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
or check IOCTL_CHANGER_GET_PRODUCT_DATA