Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Get the hard disk hardware serial number

Reply
Thread Tools

Re: Get the hard disk hardware serial number

 
 
MRAB
Guest
Posts: n/a
 
      06-03-2009
Jorge wrote:
> Hi there,
>
> I need to know how to get the hardware serial number of a hard disk in
> python.
>
> Thank you in advance.
>

For Windows, see http://www.daniweb.com/forums/thread187326.html
 
Reply With Quote
 
 
 
 
Dietmar Schwertberger
Guest
Posts: n/a
 
      06-04-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 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/forum...-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
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      06-04-2009
Dietmar Schwertberger wrote:

> The WMI method is e.g. described here:
> http://www.velocityreviews.com/forum...-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


 
Reply With Quote
 
Paul Boddie
Guest
Posts: n/a
 
      06-04-2009
On 4 Jun, 11:29, Nick Craig-Wood <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hard disk serial number Ahmed Essa ASP .Net 1 11-17-2005 05:34 PM
help plz hard disk serial number Ahmed Essa ASP .Net Security 0 11-17-2005 12:57 PM
350d serial number - what serial number?!? GT Digital Photography 6 04-07-2005 07:58 PM
copy my first hard disk info onto my second hard disk gary Computer Support 2 10-28-2004 10:49 PM
Hard disk volume serial number -- help required re editing. No Cheques Cash only Computer Support 2 01-25-2004 05:11 PM



Advertisments