• python使用wmi模块获取windows下硬盘信息


    # -*- coding: utf-8 -*- 
    #import 
    ######################################################################## 
    import os, sys 
    import time 
    import wmi 
    ######################################################################## 
    #function 
    ######################################################################## 
    def get_disk_info(): 
         """ 
         获取物理磁盘信息。 
         """ 
         tmplist = [] 
         c = wmi.WMI () 
         for physical_disk in c.Win32_DiskDrive (): 
             tmpdict = {} 
             tmpdict["Caption"] = physical_disk.Caption 
             tmpdict["Size"] = long(physical_disk.Size)/1024/1024/1024 
             tmplist.append(tmpdict) 
         return tmplist 
    def get_fs_info() : 
         """ 
         获取文件系统信息。 
         包含分区的大小、已用量、可用量、使用率、挂载点信息。 
         """ 
         tmplist = [] 
         c = wmi.WMI () 
         for physical_disk in c.Win32_DiskDrive (): 
             for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"): 
                 for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"): 
                     tmpdict = {} 
                     tmpdict["Caption"] = logical_disk.Caption 
                     tmpdict["DiskTotal"] = long(logical_disk.Size)/1024/1024/1024 
                     tmpdict["UseSpace"] = (long(logical_disk.Size)-long(logical_disk.FreeSpace))/1024/1024/1024 
                     tmpdict["FreeSpace"] = long(logical_disk.FreeSpace)/1024/1024/1024 
                     tmpdict["Percent"] = int(100.0*(long(logical_disk.Size)-long(logical_disk.FreeSpace))/long(logical_disk.Size)) 
                     tmplist.append(tmpdict) 
         return tmplist 
    if __name__ == "__main__": 
         disk = get_disk_info() 
         print disk 
         print '--------------------------------------' 
         fs = get_fs_info() 
         print fs
  • 相关阅读:
    网络编程初探
    MY GOAL
    推荐一个网站:编程资料网 http://www.ourdev.net/
    端午时节, 嘿嘿, 用论文砸自己一把
    Requirement for My Job
    MVC 才是正道, say bye to naive
    linux下的top命令参数说明 (virt,res,shr,data 的意义)
    Linux中线程与CPU核的绑定
    linux多线程域名解析函数导致的内存空间占用增长
    MD5简介
  • 原文地址:https://www.cnblogs.com/navysummer/p/13644401.html
Copyright © 2020-2023  润新知