Get the hard disk hardware serial number

Dietmar Schwertberger news at
Thu Jun 4 15:15:25 CEST 2009

MRAB schrieb:
> Jorge wrote:
>> I need to know how to get the hardware serial number of a hard disk in 
>> python.
> For Windows, see

This recipe uses the function GetVolumeInformation(), which does not
return the hardware serial number.

 From the microsoft documentation:
  This function returns the volume serial number that the operating
  system assigns when a hard disk is formatted. To programmatically
  obtain the hard disk's serial number that the manufacturer assigns,
  use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia
  property SerialNumber.

The WMI method is e.g. described here:

import wmi
c = wmi.WMI()
for pm in c.Win32_PhysicalMedia():
     print pm.Tag, pm.SerialNumber

or to retrieve the serial number for the installation drive:

serial = c.Win32_PhysicalMedia(["SerialNumber"], 



More information about the Python-list mailing list