Get SCSI and SATA hardware serial number

I need to get the hardware serial number of all types of drives on xp and win2k, I have this code

                  ManagementObjectSearcher searcher;

                  searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
                  foreach (ManagementObject wmi_HD2 in searcher.Get())

This works fine on IDE drives, but fails with an object reference not set exception when trying to get the serialnumber of a scsi or sata drive, does anyone know how to do this.

In fact it does not have to be the serial number, as long as it is a unique piece of hardware data. When I say unique, I mean each manufactured drive must have a different id of some sort.

Please note that I need the hardware serial, not the volume serial.

Actually any info on how I can identify a machine uniquely would be useful. I want to use this for locking software to a machine.

Thanks in advance
LVL 22
Who is Participating?
grayeConnect With a Mentor Commented:
That's not quiet the same as a UUID.   The UUID are guaranteed to be unique in the world.  Each manufacturer is assigned a block a numbers (actually a prefix), similarly to that of the assignment of MAC Addresses.   UUIDs were designed specifically for what you're trying to do...

A UUID is a 128-bite GUID, and looks like the following:


You are correct, the WMI provider does not provide the physical disks serial numbers... In fact the SerialNumber field of Win32_PhysicalMedia is rarely populated in modern OSs

As for the unique ID part of your question, PC manufactures have included a Universally Unique Identifier (UUID) in the BIOS for quiet some time now.  It's available using WMI from the Win32_ComputerSystemProduct class.  I *have* found a few problems with this... for example in the corporate world, we often replace a failed motherboard directly from the manufacturer.  The replaced motherboard will have a partially populated UUID until you run a utility to add the serial number into the BIOS.
RedKelvinAuthor Commented:
Hi graye, thanks for the input

I have previously played with the bios serial and have recieved ids such as "h56zb1s" do you think that is a full serial, or a partial one like you mentioned?

I used Win32_BIOS to retreive that info.

The utility you speak of, is this a special tool, that is not normally used by most users (ie. not an automatic procedure)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

BTW: The serial number of a SATA drive (and IDE drives for that matter) is the last element of that device's PnPDeviceID.   So you can use WMI's Win32_DiskDrive class to obtain the PnPDeviceID and then just trim the answer to get the serial number
RedKelvinAuthor Commented:
thanks heaps for your information graye, you have been extremely helpful, I have contructed a test module, and have been trying your ideas on various machines to see the results, promising so far, I will check out the PnPDeviceID as well now.

Let me know if you think of anything else useful.
RedKelvinAuthor Commented:
hi I ran a test and got the following info
Interface = IDE
PnP ID = IDE\DISKHTS726060M9AT00_________________________MH4OA68A\5&18BDC4CF&0&0.0.0
hardware serial = MRH403M4GRGGUB

as you can see no part of the pnp id matches the hardware serial for the drive, any ideas?

I would have thought PNP IDs would be variable?
Humm.... on my PC with SATA drives, I get


Where 2020202057202D444D5750413134353032343332 is indeed the serial number in hex

20 20 20 20 57 20 2D 44 4D 57 50 41 31 34 35 30 32 34 33 32
                  W      -    D  M  W  P   A  1   4   5   0   2  4   3   2
RedKelvinAuthor Commented:
thanks heaps for your help graye, gonna use the UUID idea
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.