Installing the Wmi,pywin32 module
#-*-coding:utf-8-*-#Import######################################################################## ImportOS, sysImport TimeImportWMI######################################################################## #function######################################################################## defget_disk_info ():"""Gets the physical disk information. """tmplist=[] C=WMI. WMI () forPhysical_diskinchc.win32_diskdrive (): Tmpdict={} tmpdict["Caption"] =Physical_disk. Caption tmpdict["Size"] = Long (physical_disk. Size)/1024/1024/1024tmplist.append (tmpdict)returntmplistdefget_fs_info ():"""Gets the file system information. Contains the size of the partition, usage, availability, utilization, mount point information. """tmplist=[] C=WMI. WMI () forPhysical_diskinchc.win32_diskdrive (): forPartitioninchPhysical_disk.associators ("win32_diskdrivetodiskpartition"): forLogical_diskinchPartition.associators ("win32_logicaldisktopartition"): Tmpdict={} tmpdict["Caption"] =Logical_disk. Caption tmpdict["Disktotal"] = Long (logical_disk. Size)/1024/1024/1024tmpdict["Usespace"] = (Long (logical_disk. Size)-long (Logical_disk. FreeSpace))/1024/1024/1024tmpdict["FreeSpace"] = Long (logical_disk. FreeSpace)/1024/1024/1024tmpdict["Percent"] = Int (100.0* (Long (logical_disk). Size)-long (Logical_disk. FreeSpace))/Long (Logical_disk. Size)) Tmplist.append (tmpdict)returntmplistif __name__=="__main__": Disk=Get_disk_info () forXinchDiskPrintxPrint '--------------------------------------'FS=Get_fs_info () forXinchFs:PrintX
The result is
{' Caption ': U ' TOSHIBA thnsnj128gcsu ', ' Size ': 119L} {' Caption ': U ' WDC wd5000lpvx-22v0tt0 ', ' Size ': 465L}--------------------------------------{' Caption ': U ' C: ', ' Percent ': Usespace ': 47L, ' disktotal ': 100L, ' FreeSpace ': 52l}{' Caption ': U ' D: ', ' Percent ':, ' usespace ': 60L, ' Dis Ktotal ': 100L, ' FreeSpace ': 39l}{' Caption ': U ' E: ', ' Percent ':, ' usespace ': 185L, ' disktotal ': 250L, ' FreeSpace ': 64l}{' Caption ': U ' F: ', ' Percent ': +, ' usespace ': 81L, ' disktotal ': 115L, ' FreeSpace ': 34L}
Python Code Learning-monitoring the win disk script