Windows View Disk Serial Number

 admin
Windows View Disk Serial Number Rating: 10,0/10 1606 votes

What you are looking at is NOT the hard drive serial number. It is called the Volume Serial Number. It is generated at the time of creating and formatting the volume / partition. You can get it by using a command at command prompt: C: > vol c: if C: is the drive you want to retrieve the Volume Serial Number for.

Active7 months ago

How to list physical disks in Windows?In order to obtain a list of '.PhysicalDrive0' available.

  1. GetDiskSerial.DLL is a standard Windows DLL that does not depend on the 'support' libraries. You can use it to read the serial number of hard disk easily. As we all know, this serial number is unique in the world. So this DLL is of great use, for example, you can use this serial number to create an machine id or encrypt number.
  2. Each box is having 4 hard disk. Now when they are in HA, I can see only 4 hard-disk, I assume because of RAID configuration. How can I find out the serial number for all my 8 Hard-disk.
Ajay
14.1k9 gold badges42 silver badges81 bronze badges
CiNNCiNN
7,3275 gold badges36 silver badges51 bronze badges

14 Answers

wmic is a very complete tool

provide a (too much) detailed list, for instance

for less info

Sebastian Godelet mentions in the comments:

In C:

As commented, you can also call the WinAPI, but.. as shown in 'How to obtain data from WMI using a C Application?', this is quite complex (and generally done with C++, not C).

Or with PowerShell:


One way to do it:

  1. Enumerate logical drives using GetLogicalDrives

  2. For each logical drive, open a file named '.X:' (without the quotes) where X is the logical drive letter.

  3. Call DeviceIoControl passing the handle to the file opened in the previous step, and the dwIoControlCode parameter set to IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS:

This returns information of the physical location of a logical volume, as a VOLUME_DISK_EXTENTS structure.

In the simple case where the volume resides on a single physical drive, the physical drive number is available in diskExtents.Extents[0].DiskNumber

GrodriguezGrodriguez
17.6k8 gold badges47 silver badges86 bronze badges

This might be 5 years too late :). But as I see no answer for this yet, adding this.

We can use Setup APIs to get the list of disks ie., devices in the system implementing GUID_DEVINTERFACE_DISK.

Once we have their device paths, we can issue IOCTL_STORAGE_GET_DEVICE_NUMBER to construct '.PHYSICALDRIVE%d' with STORAGE_DEVICE_NUMBER.DeviceNumber

See also SetupDiGetClassDevs function

Community
arunarun

The answer is far simpler than all the above answers. The physical drive list is actually stored in a Registry key which also gives the device mapping.

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesdiskEnum

Count is the number of PhysicalDrive# and each numbered Registry Value is the corresponding physical drive.

For example, Registry Value '0' is PhysicalDrive0. The value is the actual device PhysicalDrive0 is mapped to. The value contained here can be passed into CM_Locate_DevNode within parameter pDeviceID to use the plug and play services. This will allow you to gather a wealth of information on the device. Such as the properties from Device Manager like 'Friendly Display Name' if you need a name for the drive, serial numbers and more.

There is no need for WMI services which may not be running on the system or other hackery and this functionality has been present in Windows since at least 2000 and continues to be the case in Windows 10.

HooliganCoderHooliganCoder

I've modified an open-source program called 'dskwipe' in order to pull this disk information out of it. Dskwipe is written in C, and you can pull this function out of it. The binary and source are available here: dskwipe 0.3 has been released

The returned information will look something like this:

MickMick
9,2338 gold badges58 silver badges116 bronze badges

The only sure shot way to do this is to call CreateFile() on all .Physicaldiskx where x is from 0 to 15 (16 is maximum number of disks allowed). Check the returned handle value. If invalid check GetLastError() for ERROR_FILE_NOT_FOUND. If it returns anything else then the disk exists but you cannot access it for some reason.

Charles Menguy
27.5k16 gold badges82 silver badges109 bronze badges
annianni

Switched On Disk Serial Number

GetLogicalDrives() enumerates all mounted disk partitions, not physical drives.

You can enumerate the drive letters with (or without) GetLogicalDrives, then call QueryDosDevice() to find out which physical drive the letter is mapped to.

Alternatively, you can decode the information in the registry at HKEY_LOCAL_MACHINESYSTEMMountedDevices. The binary data encodings there are not obvious, however. If you have a copy of Russinovich and Solomon's book Microsoft Windows Internals, this registry hive is discussed in Chapter 10.

Die in SenteDie in Sente
7,9291 gold badge29 silver badges36 bronze badges

The only correct answer is the one by @Grodriguez, and here's a code that he was too lazy to write:

I think that installation of Windows Driver Development Kit is quite a lengthy process, so I've included the declarations one needs to use DeviceIoControl for this task.

polkovnikov.phpolkovnikov.ph
3,4134 gold badges30 silver badges66 bronze badges
Jens Erat
30.1k15 gold badges66 silver badges85 bronze badges
user2506992user2506992

Might want to include the old A: and B: drives as you never know who might be using them!I got tired of USB drives bumping my two SDHC drives that are just for Readyboost.I had been assigning them to High letters Z: Y: with a utility that will assign drive letters to devices as you wish. I wondered.. Can I make a Readyboost drive letter A: ? YES!Can I put my second SDHC drive letter as B: ? YES!

I've used Floppy Drives back in the day, never thought that A: or B: would come in handy forReadyboost.

My point is, don't assume A: & B: will not be used by anyone for anythingYou might even find the old SUBST command being used! Descargar librerias para kontakt 5 player.

liverwortliverwort

I just ran across this in my RSS Reader today. I've got a cleaner solution for you. This example is in Delphi, but can very easily be converted to C/C++ (It's all Win32).

Query all value names from the following registry location: HKLMSYSTEMMountedDevices

One by one, pass them into the following function and you will be returned the device name. Pretty clean and simple! I found this code on a blog here.

MickMick
9,2338 gold badges58 silver badges116 bronze badges

If you want 'physical' access, we're developing this API that will eventually allows you to communicate with storage devices. It's open source and you can see the current code for some information. Check back for more features:https://github.com/virtium/vtStor

phandinhlanphandinhlan
4231 gold badge4 silver badges13 bronze badges

Here is a new solution of doing it with doing WMI calls.
Then all you need to do is just to call :

Just ShadowJust Shadow
2,9471 gold badge23 silver badges31 bronze badges

Make a list of all letters in the US English Alphabet, skipping a & b. 'CDEFGHIJKLMNOPQRSTUVWXYZ'. Open each of those drives with CreateFile e.g. CreateFile('.C:'). If it does not return INVALID_HANDLE_VALUE then you got a 'good' drive. Next take that handle and run it through DeviceIoControl to get the Disk #. See my related answer for more details.

Community
unixman83unixman83
4,7779 gold badges55 silver badges93 bronze badges

Windows View Disk Serial Number Lookup

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