Windows View Disk Serial Number
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.
How to list physical disks in Windows?In order to obtain a list of '.PhysicalDrive0'
available.
- 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.
- 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.
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:
Enumerate logical drives using
GetLogicalDrives
For each logical drive, open a file named
'.X:'
(without the quotes) where X is the logical drive letter.Call
DeviceIoControl
passing the handle to the file opened in the previous step, and thedwIoControlCode
parameter set toIOCTL_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
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
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.
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:
MickMickThe 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.
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 SenteThe 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.
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.
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.
MickMickIf 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
phandinhlanphandinhlanHere is a new solution of doing it with doing WMI calls.
Then all you need to do is just to call :
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.