1.python pip安装WMI 并用pyinstaller编译出device_chk.exe
| |
| |
| |
| import os, sys |
| import wmi |
| c = wmi.WMI() |
| |
| def printCPU(): |
| tmpdict = {} |
| tmpdict["CpuCores"] = 0 |
| for cpu in c.Win32_Processor(): |
| tmpdict["cpuid"] = cpu.ProcessorId.strip() |
| tmpdict["CpuType"] = cpu.Name |
| tmpdict['systemName'] = cpu.SystemName |
| try: |
| tmpdict["CpuCores"] = cpu.NumberOfCores |
| except: |
| tmpdict["CpuCores"] += 1 |
| tmpdict["CpuClock"] = cpu.MaxClockSpeed |
| tmpdict['DataWidth'] = cpu.DataWidth |
| print ("---处理器") |
| print (tmpdict) |
| return tmpdict |
| |
| |
| def printMain_board(): |
| boards = [] |
| |
| for board_id in c.Win32_BaseBoard(): |
| tmpmsg = {} |
| tmpmsg['UUID'] = board_id.qualifiers['UUID'][1:-1] |
| tmpmsg['SerialNumber'] = board_id.SerialNumber |
| tmpmsg['Manufacturer'] = board_id.Manufacturer |
| tmpmsg['Product'] = board_id.Product |
| boards.append(tmpmsg) |
| print("---主板") |
| print (boards) |
| return boards |
| |
| |
| def printBIOS(): |
| bioss = [] |
| for bios_id in c.Win32_BIOS(): |
| tmpmsg = {} |
| tmpmsg['BiosCharacteristics'] = bios_id.BiosCharacteristics |
| tmpmsg['version'] = bios_id.Version |
| tmpmsg['Manufacturer'] = bios_id.Manufacturer.strip() |
| tmpmsg['ReleaseDate'] = bios_id.ReleaseDate |
| tmpmsg['SMBIOSBIOSVersion'] = bios_id.SMBIOSBIOSVersion |
| bioss.append(tmpmsg) |
| print("---BIOS") |
| print (bioss) |
| return bioss |
| |
| |
| def printDisk(): |
| disks = [] |
| print("---硬盘") |
| for disk in c.Win32_DiskDrive(): |
| |
| tmpmsg = {} |
| tmpmsg['SerialNumber'] = disk.SerialNumber.strip() |
| tmpmsg['DeviceID'] = disk.DeviceID |
| tmpmsg['Caption'] = disk.Caption |
| tmpmsg['Size'] = disk.Size |
| tmpmsg['UUID'] = disk.qualifiers['UUID'][1:-1] |
| disks.append(tmpmsg) |
| for d in disks: |
| print (d) |
| return disks |
| |
| |
| def printPhysicalMemory(): |
| memorys = [] |
| print ("---内存") |
| for mem in c.Win32_PhysicalMemory(): |
| tmpmsg = {} |
| tmpmsg['UUID'] = mem.qualifiers['UUID'][1:-1] |
| tmpmsg['BankLabel'] = mem.BankLabel |
| tmpmsg['SerialNumber'] = mem.SerialNumber.strip() |
| |
| tmpmsg['Capacity'] = mem.Capacity |
| |
| memorys.append(tmpmsg) |
| for m in memorys: |
| print (m) |
| return memorys |
| |
| |
| def printBattery(): |
| isBatterys = False |
| for b in c.Win32_Battery(): |
| isBatterys = True |
| return isBatterys |
| |
| |
| def printMacAddress(): |
| macs = [] |
| for n in c.Win32_NetworkAdapter(): |
| mactmp = n.MACAddress |
| if mactmp and len(mactmp.strip()) > 5: |
| tmpmsg = {} |
| tmpmsg['MACAddress'] = n.MACAddress |
| tmpmsg['Name'] = n.Name |
| tmpmsg['DeviceID'] = n.DeviceID |
| tmpmsg['AdapterType'] = n.AdapterType |
| tmpmsg['Speed'] = n.Speed |
| macs.append(tmpmsg) |
| print("---网卡") |
| print (macs) |
| return macs |
| |
| def main(): |
| |
| printCPU() |
| printMain_board() |
| printBIOS() |
| printDisk() |
| printPhysicalMemory() |
| printMacAddress() |
| |
| |
| |
| if __name__ == '__main__': |
| main() |
2.bat输出打印信息至文本
| device_chk.exe > 1.txt 2>&1 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端