onlyforbopi
4/22/2019 - 11:43 AM

Python.Module.Win32

Python.Modules.Win32 #drive #drives #ListofDrives #NumberofDrives #NamedDrives #Flash #USB #UnnamedDrives #UnreachableDrivesPython.Modules.Win32

#-*- coding: utf-8 -*-
# """
# Created on Fri Mar 31 09:49:49 2017

# @author: P.Doulgeridis
# """



import os
import sys
import ctypes
import win32api
#import win32com.client






# ###################################
# Program Vars

NOfDrives = 0
NOfReachDrives = 0
NOfUnReachDrives = 0
NOfNamedDrives = 0
NOfUnamedDrives = 0

LOfDrives = []
LOfReachDrives = []
LOfUnReachDrives = []
LOfNamedDrives = []
LOfUnamedDrives = []

drive_mapping = dict()
named_mapping = dict()

# Get list of drives
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
print (drives)



print("aaaa")

kernel32 = ctypes.windll.kernel32
buf = ctypes.create_unicode_buffer(1024)
win32api.GetVolumeInformation("E:\\")


print(str(win32api.GetVolumeInformation("C:\\")))
# print(str(win32api.GetVolumeInformation("D:\\")))
print(str(win32api.GetVolumeInformation("E:\\")))
print(str(win32api.GetVolumeInformation("F:\\")))
print(str(win32api.GetVolumeInformation("Y:\\")))


for drive in drives:
    #print(str(win32api.GetVolumeInformation(str(drive))))
    
    NOfDrives += 1
    LOfDrives.append(drive)
    
    try:
        spec_drive = win32api.GetVolumeInformation(drive)
        NOfReachDrives += 1
        LOfReachDrives.append(drive)
        drive_mapping[drive] = ''
    except:
        print("Drive: " + str(drive) + " is unreachable. Or you do not have permission to read it.")
        NOfUnReachDrives+= 1
        LOfUnReachDrives.append(drive)
        drive_mapping[drive] = 'unreachable'
    
for drive in LOfReachDrives:
    
    try:
        drive_tup = win32api.GetVolumeInformation(drive)
        #print(drive_tup)
    except:
        print(error)
    else:
        name_check = drive_tup[0]
        #print(name_check)
        
        if str(name_check) != '':
            NOfNamedDrives += 1
            LOfNamedDrives.append(drive)
            #print(name_check)
            drive_mapping[drive] = name_check
            named_mapping[drive] = name_check
        else:
            NOfUnamedDrives += 1
            LOfUnamedDrives.append(drive)
            drive_mapping[drive] = 'unmapped'

            
print(LOfNamedDrives)
print(drive_mapping)


print("\n@Report:\n")
print("Number of drives located: " + str(NOfDrives))
print("List of located drives: " + str(LOfDrives)) 
print("\nNumber of named drives located: " + str(NOfNamedDrives))
print("List of named located drives: " + str(LOfNamedDrives)) 
print("\nNumber of unamed drives located: " + str(NOfUnamedDrives))
print("List of unamed located drives: " + str(LOfUnamedDrives)) 
print("\nNumber of unreachable drives located: " + str(NOfUnReachDrives))
print("List of unreachable drives: " + str(LOfUnReachDrives))
print("Dictionary mapping of all drives and names:" + str(drive_mapping))
print("Dictionary mapping of named drives only: " + str(named_mapping)) 
import win32com.client 
strComputer = "." 
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") 
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") 
colItems = objSWbemServices.ExecQuery("Select * from Win32_LogicalDisk") 
for objItem in colItems:
    print("\n@@@@@Processing drive: " + str(objItem.Caption)) 
    print ("Access: ", objItem.Access) 
    print ("Availability: ", objItem.Availability) 
    print ("Block Size: ", objItem.BlockSize)
    print ("Caption: ", objItem.Caption) 
    print ("Compressed: ", objItem.Compressed)
    print ("Config Manager Error Code: ", objItem.ConfigManagerErrorCode) 
    print ("Config Manager User Config: ", objItem.ConfigManagerUserConfig) 
    print ("Creation Class Name: ", objItem.CreationClassName )
    print ("Description: ", objItem.Description )
    print ("Device ID: ", objItem.DeviceID )
    print ("Drive Type: ", objItem.DriveType )
    print ("Error Cleared: ", objItem.ErrorCleared )
    print ("Error Description: ", objItem.ErrorDescription )
    print ("Error Methodology: ", objItem.ErrorMethodology )
    print ("File System: ", objItem.FileSystem )
    print ("Free Space: ", objItem.FreeSpace )
    print ("Install Date: ", objItem.InstallDate )
    print ("Last Error Code: ", objItem.LastErrorCode )
    print ("Maximum Component Length: ", objItem.MaximumComponentLength ) 
    print ("Media Type: ", objItem.MediaType )
    print ("Name: ", objItem.Name )
    print ("Number Of Blocks: ", objItem.NumberOfBlocks ) 
    print ("PNP Device ID: ", objItem.PNPDeviceID ) 
    z = objItem.PowerManagementCapabilities  
    if z is None: 
        a = 1 
    else: 
        for x in z: 
            print ("Power Management Capabilities: ", x )
    print ("Power Management Supported: ", objItem.PowerManagementSupported )
    print ("Provider Name: ", objItem.ProviderName )
    print ("Purpose: ", objItem.Purpose )
    print ("Quotas Disabled: ", objItem.QuotasDisabled )
    print ("Quotas Incomplete: ", objItem.QuotasIncomplete )
    print ("Quotas Rebuilding: ", objItem.QuotasRebuilding )
    print ("Size: ", objItem.Size )
    print ("Status: ", objItem.Status )
    print ("Status Info: ", objItem.StatusInfo )
    print ("Supports Disk Quotas: ", objItem.SupportsDiskQuotas )
    print ("Supports File-Based Compression: ", objItem.SupportsFileBasedCompression )
    print ("System Creation Class Name: ", objItem.SystemCreationClassName )
    print ("System Name: ", objItem.SystemName )
    print ("Volume Dirty: ", objItem.VolumeDirty )
    print ("Volume Name: ", objItem.VolumeName )
    print ("Volume Serial Number: ", objItem.VolumeSerialNumber )