How To Find Hard Drive Serial Number

I want to get hard disk serial number. How I can I do that?I tried with two code but I am not getting

In this one I am not getting any Unique Serial number.
And Second one is

Here I am getting VolumeSerialNumber. But it is not unique one. If I format the hard disk, this will change. How Can I get this?

Muhammad Saqib

How to Find a Drive's Volume Label or Serial Number From the Command Prompt. Open Command Prompt. Command Prompt is located in the Accessories program group in the Start Menu of Windows 7, Windows Vista, and Windows XP. In Windows 10 and Windows 8, right-click or tap-and-hold on the Start button to find Command Prompt.

1,1181 gold badge24 silver badges39 bronze badges
JobyJoby
1741 gold badge2 silver badges10 bronze badges

10 Answers

Hm, looking at your first set of code, I think you have retrieved (maybe?) the hard drive model. The serial # comes from Win32_PhysicalMedia.

Get Hard Drive model

Get the Serial Number

Hope this helps :)

hims056
23.6k23 gold badges93 silver badges120 bronze badges
SprunthSprunth

I have used the following method in a project and it's working successfully.

How To Find Hard Drive Serial Number Lookup

you can call the above method as mentioned below,

How To Find Western Digital Hard Drive Serial Number

If you need a unique identifier, use a combination of these IDs.

How To Find Hard Drive Serial NumberSency

Western Digital

Sency
1,0776 gold badges30 silver badges54 bronze badges
huoxudong125huoxudong125
1,0332 gold badges15 silver badges37 bronze badges

Use 'vol' shell command and parse serial from it's output, like this.Works at least in Win7

PeksuPeksu
Tot Zam
4,1744 gold badges34 silver badges54 bronze badges

Hard Drive Serial Number Software

Brahim BourassBrahim Bourass

The best way I found is, download a dll from here

Then, add the dll to your project.

Then, add code:

Then, call the hard disk ID from where you need it

Note: go to properties of the dll in explorer and set 'Build action' to 'Embedded Resource'

Brian Webster
21k41 gold badges132 silver badges208 bronze badges
Azhar BandriAzhar Bandri

Below a fully functional method to get hard disk serial number:

How To Find Hard Drive Serial Number List

Anjan KantAnjan Kant
lxg
8,80511 gold badges31 silver badges54 bronze badges
Denis IlyushchenkoDenis Ilyushchenko
Hard

Here is a solution using win32 api and std string in case you need your application to run on a OS with no CLR. I found it here on github.

IjonTichyIjonTichy

In case you want to use it for copy protection and you need it to return always the same serial on one computer (of course as far as first hdd or ssd is not changed) I would recommend code below. For ManagementClass you need to add reference to System.Management. P.S. Without 'InterfaceType' and 'DeviceID' check that method can return serial of random disk or serial of USB flash drive which connected to pc right now.

random onerandom one

Not the answer you're looking for? Browse other questions tagged c#hard-drive or ask your own question.