Re: Get the hard disk hardware serial number

Discussion in 'Python' started by MRAB, Jun 3, 2009.

  1. MRAB

    MRAB Guest

    MRAB, Jun 3, 2009
    #1
    1. Advertising

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

    > For Windows, see http://www.daniweb.com/forums/thread187326.html


    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:
    http://www.velocityreviews.com/forums/t359670-wmi-help.html


    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"],
    Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip()


    Regards,

    Dietmar
     
    Dietmar Schwertberger, Jun 4, 2009
    #2
    1. Advertising

  3. MRAB

    Terry Reedy Guest

    Dietmar Schwertberger wrote:

    > The WMI method is e.g. described here:
    > http://www.velocityreviews.com/forums/t359670-wmi-help.html
    >
    >
    > import wmi


    Not in the stdlib, but available here:
    http://pypi.python.org/pypi/WMI/1.3
    and requires in turn pywin32:
    http://pypi.python.org/pypi/pywin32/210

    > 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"],
    > Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip()
    >
    >
    > Regards,
    >
    > Dietmar
     
    Terry Reedy, Jun 4, 2009
    #3
  4. MRAB

    Paul Boddie Guest

    On 4 Jun, 11:29, Nick Craig-Wood <> wrote:
    >
    > For linux I'd run this and parse the results.
    >
    > # smartctl -i /dev/sda


    Also useful is hdparm, particularly with the drive identification and
    detailed information options shown respectively below:

    # hdparm -i /dev/sda
    # hdparm -I /dev/sda

    Paul
     
    Paul Boddie, Jun 4, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Essa

    hard disk serial number

    Ahmed Essa, Nov 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    533
    Nick Hertl
    Nov 17, 2005
  2. Guest

    hard disk serial

    Guest, May 25, 2004, in forum: Python
    Replies:
    2
    Views:
    360
    Guest
    May 25, 2004
  3. David Stockwell

    Re: hard disk serial

    David Stockwell, May 25, 2004, in forum: Python
    Replies:
    0
    Views:
    380
    David Stockwell
    May 25, 2004
  4. Replies:
    0
    Views:
    345
  5. Ahmed Essa

    help plz hard disk serial number

    Ahmed Essa, Nov 17, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    146
    Ahmed Essa
    Nov 17, 2005
Loading...

Share This Page