首页 > 编程语言 > 详细

Python 获取U盘的序列号

时间:2020-05-11 14:38:17      阅读:421      评论:0      收藏:0      [点我收藏+]

是根据盘符获取的U盘序列号:

import psutil
import win32api
from io import StringIO

def run():
    uf = StringIO()
    while True:
        disk_list = []
        for item in psutil.disk_partitions():
            # 判断是不是U盘
            if "removable" in item.opts:
                # 获取U盘的盘符
                disk_list.append(item.mountpoint)
        # 把盘符写入内存,为了不持续请求
        if disk_list != []:
            for pf in disk_list:
                if pf not in uf.getvalue():
                    print("U盘插入")
                    uf.write(disk_list[0])
                    """考虑插多个u盘"""
                    seriaNumber = win32api.GetVolumeInformation(pf)
                    print(f"U盘序列号:{seriaNumber[1]}")

        else:
            # 拔出u盘初始化内存
            uf = StringIO(hello)
            print("U盘拔出")


if __name__ == "__main__":
    run()

 

Python 获取U盘的序列号

原文:https://www.cnblogs.com/txmblog/p/12868747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!