• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1320
  • Last Modified:

Get SCSI and SATA hardware serial number

Hi,
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())
                  {
                              Console.WriteLine(wmi_HD2["SerialNumber"].ToString());
                  }

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
0
RedKelvin
Asked:
RedKelvin
  • 4
  • 4
1 Solution
 
grayeCommented:
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.
0
 
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)
0
 
grayeCommented:
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:

E1C43508-C6E4-11D8-9203-547922D96191

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
grayeCommented:
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
0
 
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.
0
 
RedKelvinAuthor Commented:
hi I ran a test and got the following info
Interface = IDE
Device ID = \\.\PHYSICALDRIVE0
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?
0
 
grayeCommented:
Humm.... on my PC with SATA drives, I get

IDE\DISKWDC_WD1500ADFD-00NLR0___________________19.06P19\2020202057202D444D5750413134353032343332

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
0
 
RedKelvinAuthor Commented:
thanks heaps for your help graye, gonna use the UUID idea
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now