关闭

python get registry infomation

247人阅读 评论(0) 收藏 举报
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


http://mail.python.org/pipermail/python-list/2002-August/735262.html

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6976次
    • 积分:180
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档