[英]Getting manufacturer serialnumber of system harddrive with WMI
I want to get the manufacturer serialnumber of my system HDD using WMI in my c++ project. 我想在我的c ++项目中使用WMI获取系统硬盘的制造商序列号。
I am already able to query the SerialNumber from the Win32_DiskDrive Class. 我已经能够从Win32_DiskDrive类中查询SerialNumber。 However, this returns four serial numbers because I have four HDD.
但是,这会返回四个序列号,因为我有四个硬盘。 I only want to know the HDD serialnumber of my system disk but I am not able to format the right query.
我只想知道系统盘的硬盘序列号,但我无法格式化正确的查询。
Anyone done this before and knows how to construct this query? 以前做过这个的人都知道如何构建这个查询?
Use Win32_DiskPartition to retrieve the DiskIndex
Property and use it to query Win32_DiskDrive with it's Index
property. 使用Win32_DiskPartition检索
DiskIndex
属性并使用它来查询Win32_DiskDrive及其Index
属性。
Both are Uint32
. 两者都是
Uint32
。
This SO Answer describes a way of retrieving DiskDrives associated to volumes. 本SO答案描述了一种检索与卷关联的DiskDrives的方法。
Also "How can I correlate logical drives and physical Drives" on TechNet may help. TechNet上的“我如何关联逻辑驱动器和物理驱动器”可能会有所帮助。
First you have to figure out what is your SystemDrive
and then query other WMI table to get the serialNumber
. 首先,您必须弄清楚什么是您的
SystemDrive
,然后查询其他WMI表以获取serialNumber
。 WMI keeps serialnumber in many tables, you have to make a better choice regarding which table can fulfill your use case. WMI在许多表中保留序列号,您必须更好地选择哪个表可以满足您的用例。 If serialNumber is your only use case then query
Win32_LogicalDisk
, if not, write a comment and we can work from there :) 如果serialNumber是你唯一的用例然后查询
Win32_LogicalDisk
,如果没有,写一个评论,我们可以从那里工作:)
Select SystemDrive from Win32_OperatingSystem
Select VolumeSerialNumber FROM Win32_LogicalDisk where (DriveType = '2' or DriveType = '3') AND deviceid= '<SystemDrive>'
Updated 更新
Select Index from Win32_DiskPartition where BootPartition ='TRUE'
Select SerialNumber from Win32_DiskDrive where index='<Index>'
Note: Give it a dry run for couple of machines. 注意:为几台机器进行干运行。
1.GetSystemDirectory() get system Partition.For example, C:\\Windows\\System32 and C: is System partition. 1.GetSystemDirectory()获取系统分区。例如,C:\\ Windows \\ System32和C:是系统分区。
2.Get DiskIndex of System partition from Win32_DiskPartition 2.从Win32_DiskPartition获取系统分区的DiskIndex
3.Get SerialNumber from Win32_DiskDrive which DiskIndex is step 2 3.从Win32_DiskDrive获取SerialNumber,DiskIndex是第2步
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.