python get registry infomation

本文介绍了如何使用Python获取硬盘的硬件序列号,包括针对Windows系统的具体步骤及使用WMI方法获取制造商分配的序列号。
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

 

 

../canvas@2.11.2/node_modules/canvas install$ node-pre-gyp install --fallback-to-build --update-binary │ node-pre-gyp info it worked if it ends with ok │ node-pre-gyp info using node-pre-gyp@1.0.11 │ node-pre-gyp info using node@22.10.0 | win32 | x64 │ (node:19796) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative i… │ (Use `node --trace-deprecation ...` to show where the warning was created) │ node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v127-… │ node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/downl… │ node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and node@22.10.0 (node-v127 ABI, unknown) (f… │ node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/dow… │ gyp info it worked if it ends with ok │ gyp info using node-gyp@10.1.0 │ gyp info using node@22.10.0 | win32 | x64 │ gyp info ok │ gyp info it worked if it ends with ok │ gyp info using node-gyp@10.1.0 │ gyp info using node@22.10.0 | win32 | x64 │ gyp ERR! find Python │ gyp ERR! find Python Python is not set from command line or npm configuration │ gyp ERR! find Python Python is not set from environment variable PYTHON │ gyp ERR! find Python checking if the py launcher can be used to find Python 3 │ gyp ERR! find Python - executable path is "" │ gyp ERR! find Python - "" could not be run │ gyp ERR! find Python checking if "python3" can be used │ gyp ERR! find Python - executable path is "" │ gyp ERR! find Python - "" could not be run │ gyp ERR! find Python checking if "python" can be used │ gyp ERR! find Python - executable path is "" │ gyp ERR! find Python - "" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python311\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python311\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python311\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python311\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python311-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python311-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python311-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python311-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python311-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files (x86)\Python311-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python310\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python310\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python310\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python310\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python310-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python310-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python310-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python310-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python310-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files (x86)\Python310-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python39\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python39\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python39\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python39\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python39-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python39-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python39-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python39-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python39-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files (x86)\Python39-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python38\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python38\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python38\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python38\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Users\18751\AppData\Local\Programs\Python\Python38-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Users\18751\AppData\Local\Programs\Python\Python38-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files\Python38-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files\Python38-32\python.exe" could not be run │ gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python38-32\python.exe │ gyp ERR! find Python - version is "" │ gyp ERR! find Python - version is - should be >=3.6.0 │ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED │ gyp ERR! find Python - "C:\Program Files (x86)\Python38-32\python.exe" could not be run │ gyp ERR! find Python │ gyp ERR! find Python ********************************************************** │ gyp ERR! find Python You need to install the latest version of Python. │ gyp ERR! find Python Node-gyp should be able to find and use Python. If not, │ gyp ERR! find Python you can try one of the following options: │ gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe" │ gyp ERR! find Python (accepted by both node-gyp and npm) │ gyp ERR! find Python - Set the environment variable PYTHON │ gyp ERR! find Python - Set the npm configuration variable python: │ gyp ERR! find Python npm config set python "C:\Path\To\python.exe" │ gyp ERR! find Python For more information consult the documentation at: │ gyp ERR! find Python https://github.com/nodejs/node-gyp#installation │ gyp ERR! find Python ********************************************************** │ gyp ERR! find Python │ gyp ERR! configure error │ gyp ERR! stack Error: Could not find any Python installation to use │ gyp ERR! stack at PythonFinder.fail (D:\projects\nvm\nvm\v22.10.0\node_modules\pnpm\dist\node_modules\node-gyp\lib\… │ gyp ERR! stack at PythonFinder.findPython (D:\projects\nvm\nvm\v22.10.0\node_modules\pnpm\dist\node_modules\node-gy… │ gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:105:5) │ gyp ERR! stack at async configure (D:\projects\nvm\nvm\v22.10.0\node_modules\pnpm\dist\node_modules\node-gyp\lib\co… │ gyp ERR! stack at async run (D:\projects\nvm\nvm\v22.10.0\node_modules\pnpm\dist\node_modules\node-gyp\bin\node-gyp… │ gyp ERR! System Windows_NT 10.0.26100 │ gyp ERR! command "D:\\projects\\nvm\\nodejs\\node.exe" "D:\\projects\\nvm\\nvm\\v22.10.0\\node_modules\\pnpm\\dist\… │ gyp ERR! cwd D:\projects\fuzhou\fuzhou.project-all-app\node_modules\.pnpm\canvas@2.11.2\node_modules\canvas │ gyp ERR! node -v v22.10.0 │ gyp ERR! node-gyp -v v10.1.0 │ gyp ERR! not ok │ node-pre-gyp ERR! build error │ node-pre-gyp ERR! stack Error: Failed to execute 'D:\projects\nvm\nodejs\node.exe D:\projects\nvm\nvm\v22.10.0\node… │ node-pre-gyp ERR! stack at ChildProcess.<anonymous> (D:\projects\fuzhou\fuzhou.project-all-app\node_modules\.pn… │ node-pre-gyp ERR! stack at ChildProcess.emit (node:events:518:28) │ node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1104:16) │ node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:304:5) │ node-pre-gyp ERR! System Windows_NT 10.0.26100 │ node-pre-gyp ERR! command "D:\\projects\\nvm\\nodejs\\node.exe" "D:\\projects\\fuzhou\\fuzhou.project-all-app\\node… │ node-pre-gyp ERR! cwd D:\projects\fuzhou\fuzhou.project-all-app\node_modules\.pnpm\canvas@2.11.2\node_modules\canvas │ node-pre-gyp ERR! node -v v22.10.0 │ node-pre-gyp ERR! node-pre-gyp -v v1.0.11 │ node-pre-gyp ERR! not ok │ Failed to execute 'D:\projects\nvm\nodejs\node.exe D:\projects\nvm\nvm\v22.10.0\node_modules\pnpm\dist\node_modules… └─ Failed in 1.3s at D:\projects\fuzhou\fuzhou.project-all-app\node_modules\.pnpm\canvas@2.11.2\node_modules\canvas  ELIFECYCLE  Command failed with exit code 1.
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值