Heimmot
Heimmot

Reputation: 45

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.

I am already able to query the SerialNumber from the Win32_DiskDrive Class. 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?

Upvotes: 1

Views: 2077

Answers (3)

Jack
Jack

Reputation: 161

1.GetSystemDirectory() get system Partition.For example, C:\Windows\System32 and C: is System partition.

2.Get DiskIndex of System partition from Win32_DiskPartition

3.Get SerialNumber from Win32_DiskDrive which DiskIndex is step 2

Upvotes: 0

Amit Shakya
Amit Shakya

Reputation: 1476

First you have to figure out what is your SystemDrive and then query other WMI table to get the serialNumber. WMI keeps serialnumber in many tables, you have to make a better choice regarding which table can fulfill your use case. If serialNumber is your only use case then query Win32_LogicalDisk, if not, write a comment and we can work from there :)

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.

Upvotes: 2

Clijsters
Clijsters

Reputation: 4256

To get your System HDD, first you have to find out which Hard Disk holds your System Partition.


Use Win32_DiskPartition to retrieve the DiskIndex Property and use it to query Win32_DiskDrive with it's Index property.

Both are Uint32.

This SO Answer describes a way of retrieving DiskDrives associated to volumes.

Also "How can I correlate logical drives and physical Drives" on TechNet may help.

Upvotes: 0

Related Questions