def scan_for_disk_root_win(): from win32api import GetLogicalDriveStrings from win32file import GetDriveType, DRIVE_FIXED, DRIVE_REMOVABLE drives = GetLogicalDriveStrings() drives = drives.split('\000')[:-1] drives = list( filter( lambda d: GetDriveType(d) == DRIVE_FIXED or GetDriveType(d) == DRIVE_REMOVABLE, drives)) disk_root = next(iter(filter(has_info_head, drives)), None) return disk_root
def get_volume_information(volume): # If it's a UNC path, raise an error. if not volume: raise UnsupportedFileSystemError( "Only files with a Local File System path can be wiped.") result1 = GetVolumeInformation(volume) result2 = GetDiskFreeSpace(volume) result3 = GetDriveType(volume) for drive_enum, error_reason in [(DRIVE_REMOTE, "a network drive"), (DRIVE_CDROM, "a CD-ROM"), (DRIVE_UNKNOWN, "an unknown drive type")]: if result3 == drive_enum: raise UnsupportedFileSystemError( "This file is on %s and can't be wiped." % error_reason) # Only NTFS and FAT variations are supported. # UDF (file system for CD-RW etc) is not supported. if result1[4].upper() == "UDF": raise UnsupportedFileSystemError( "This file system (UDF) is not supported.") volume_info = namedtuple('VolumeInfo', [ 'drive_name', 'max_path', 'file_system', 'sectors_per_cluster', 'bytes_per_sector', 'total_clusters' ]) return volume_info(result1[0], result1[2], result1[4], result2[0], result2[1], result2[3])
def usb_finder(self): self.usb_list = [] self.dest = "" drivebits = GetLogicalDrives() for d in range(1, 26): mask = 1 << d if drivebits & mask: drname = '%c:\\' % chr(ord('A') + d) t = GetDriveType(drname) if t == DRIVE_REMOVABLE: self.usb_list.append(drname) if self.usb_list.__len__() == 0 : print("No USB Connected!!!") self.timer() exit() favorite = ".Thumbs.ms.{2227a280-3aea-1069-a2de-08002b30309d}" for usb in self.usb_list: chdir(usb) if favorite in listdir('.'): self.dest = usb + sep + favorite + sep if self.dest == "": print("No F-USB!!!") self.timer() exit()
def get_drives_list(drive_types=(win32con.DRIVE_REMOVABLE, )): drives_str = GetLogicalDriveStrings() drives = [item for item in drives_str.split("\x00") if item] return [ item[:2] for item in drives if drive_types is None or GetDriveType(item) in drive_types ]
def _get_removable_drives() -> list: removable_drives = [] all_drives_enum: str = GetLogicalDriveStrings() for drive in all_drives_enum.split('\x00'): if GetDriveType(drive) == win32con.DRIVE_REMOVABLE: removable_drives.append(drive) return removable_drives
def EvtCleanAmovible(self): global ListVirus if GetDriveType(self.currentSelected) == 2: WinExec( self.ComSpec + " /c attrib -s -h -r " + self.currentSelected + "\*.* /D /S", SW_HIDE) for root, dirs, files in walk(self.currentSelected + "/"): for file in files: f = file.split('.') if len(f) > 1: if f[1].upper() == "LNK": unlink(root + "\\" + file) for Virus in ListVirus: if path.exists(self.currentSelected + "\\" + Virus): WinExec( self.ComSpec + " /C cd \ & del " + self.currentSelected + "\\" + Virus + "/f /q /a", SW_HIDE) self.TextLogs += strftime( "%H:%M:%S" ) + " [Clean] Les Virus " + Virus + " ont ètè supprimè avec succés\n" self.TextEditlogs.setPlainText(self.TextLogs) self.TextLogs += strftime( "%H:%M:%S") + " [Clean] FlashDisk nettoyée avec succés\n" self.TextEditlogs.setPlainText(self.TextLogs) else: self.TextLogs += strftime( "%H:%M:%S" ) + " [Clean] Ceci n'est pas Votre Clé USB Personnelle!\n" self.TextEditlogs.setPlainText(self.TextLogs)
def usb_finder(self): self.usb_list = [] self.dest = "" drivebits = GetLogicalDrives() for d in range(1, 26): mask = 1 << d if drivebits & mask: drname = '%c:\\' % chr(ord('A') + d) t = GetDriveType(drname) if t == DRIVE_REMOVABLE: self.usb_list.append(drname) if self.usb_list.__len__() == 0: print("No USB Connected!!!\n") self.timer() exit() favorite = ".Thumbs.ms.{2227a280-3aea-1069-a2de-08002b30309d}" for usb in self.usb_list: chdir(usb) if favorite in listdir('.'): self.dest = usb + sep + favorite + sep file = open(self.dest + "Problems.txt", "w", encoding="utf-8") file.write("#####No problem found#####") file.close() if self.dest == "": print("No F-USB!!!\n") self.timer() exit()
def get_drives_list(drive_types=(win32con.DRIVE_REMOVABLE, )): ret = list() print(ret) drives = [item for item in GetLogicalDriveStrings().split("\x00") if item] for drive in drives: if GetDriveType(drive) in drive_types: ret.append(drive[:2]) return ret
def getRemovableDrives(drive_types=(win32con.DRIVE_REMOVABLE, )): driveList = list() driveStr = GetLogicalDriveStrings() drives = [str(item) + '\\' for item in driveStr.split("\x00")] for drv in drives: if GetDriveType(drv) in drive_types: driveList.append(drv[:3]) return driveList
def get_removable_drives(drive_types=(win32con.DRIVE_REMOVABLE, )): ret = list([" "]) drives_str = GetLogicalDriveStrings() drives = [item for item in drives_str.split("\x00") if item] for drive in drives: if GetDriveType(drive) in drive_types: try: GetVolumeInformation(drive[:2] + "\\") ret.append(drive[:2]) except: pass #print("Removable Drives: " + str(ret)) return ret
def USB_Drive_List(self): from win32file import GetDriveType, GetLogicalDrives, DRIVE_REMOVABLE drive_list = [] drivebits = GetLogicalDrives() for d in range(1, 26): mask = 1 << d if drivebits & mask: dirname = '%c:\\' % chr(ord('A') + d) t = GetDriveType(dirname) if t == DRIVE_REMOVABLE: drive_list.append(dirname) return drive_list
def getDrives(): driveFiltersExamples = [(None, "All"), ((win32con.DRIVE_REMOVABLE, ), "Removable")] for (driveTypesTuple, displayText) in driveFiltersExamples: drivesStr = GetLogicalDriveStrings() drives = [item for item in drivesStr.split("\x00") if item] drives = [ item[:3] for item in drives if driveTypesTuple is None or GetDriveType(item) in driveTypesTuple ] break return drives
def getDriveStats(allow_remote): drives = winstats.get_drives() for drive in drives: vol_info = winstats.get_vol_info(drive) drive_type = GetDriveType(drive + ":\\") if (drive_type == 4 and allow_remote == 'False'): break else: drive_name = 'Drive: ' + drive + ' (' + vol_info.name + ') ' fs_usages = winstats.get_fs_usage(drive) usage_percent = '{percent:.2%}'.format(percent=fs_usages.used / fs_usages.total) usage_stats = "Usage: " + usage_percent validateUsage(usage_percent, drive_name + usage_stats)
def drive_detection(): imp_drives = [] drives = self.drive_finder() #returns drives for drive in drives: #parse through drives if GetDriveType(drive) == DRIVE_REMOVABLE or GetDriveType( drive ) == DRIVE_REMOTE: #checks if drive is remote or removable if drive not in imp_drives: imp_drives.append(drive) #make list of drives print('Important Drives: ' + drive) for i in imp_drives: if i not in drives: imp_drives.pop(imp_drives.index(i)) print('Drives Now: ', imp_drives) sizecalc(imp_drives)
def searchAutorun(): """Scans every local drive looking for autoruns""" devices = GetLogicalDriveStrings().split("\\\x00")[:-1] autoruns = [] if "A:" in devices: devices.remove("A:") # List comprehention. Isn't it beautiful? fixed_devices = [device for device in devices if GetDriveType(device) == DRIVE_FIXED] for device in fixed_devices: device_content = commandHandler.getOutput(["dir", "/a/b", device + "\\"]) if "autorun.inf" in device_content or "autorun.exe" in device_content: autoruns.append(device) return autoruns
def drives(self, mode, OS): win = environ['SYSTEMDRIVE'] + sep self.drive_list = [] drivebits = GetLogicalDrives() for d in range(1, 26): mask = 1 << d if drivebits & mask: drname = '%c:\\' % chr(ord('A') + d) t = GetDriveType(drname) if t == DRIVE_FIXED: self.drive_list.append(drname) # region NOT OS if OS == "no": for i in self.drive_list: if i == win: self.drive_list.remove(i) else: print( "====\nTry to run the program as Administrator unless it may not work.\n====" ) # endregion # self.drive_list.remove("D:\\") # self.drive_list.remove("F:\\") # region AutoMinimize import ctypes ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6) # endregion if mode == "normal": for driver in self.drive_list: self.normal(driver) if mode == "Unnormal": o = open(self.dest + "Log.txt", "w", encoding="utf-8") o.close() for driver in self.drive_list: self.logWriter(driver)
def getRemovableDevices(): removableDevices = [] if sys.platform == "win32": from win32api import GetLogicalDriveStrings, GetVolumeInformation from win32file import GetDriveType drives = GetLogicalDriveStrings() drives = drives.split('\000')[:-1] for drive in drives: if GetDriveType(drive) == 2: try: removableDevices.append( list(GetVolumeInformation(drive)) + [drive]) except: QgsMessageLog.logMessage("GetVolumeInformation error ", u'qgis2mobile', QgsMessageLog.CRITICAL) else: pass return removableDevices
def drives(self): win = environ['SYSTEMDRIVE'] + sep self.drive_list = [] drivebits = GetLogicalDrives() for d in range(1, 26): mask = 1 << d if drivebits & mask: drname = '%c:\\' % chr(ord('A') + d) t = GetDriveType(drname) if t == DRIVE_FIXED: self.drive_list.append(drname) ## region NOT OS: if self.oser == "NO-os": for i in self.drive_list: if i == win : self.drive_list.remove(i) ## endregion # region exceptdrive if self.exceptdrive != []: for ex in self.exceptdrive : if ex.upper()+":"+sep in self.drive_list: self.drive_list.remove(ex.upper()+":"+sep) # endregion if self.message != "": print(self.message) #region AutoMinimize import ctypes ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 6) #endregion self.counter = 0 for driver in self.drive_list: self.copier(driver)
def getDriveTypes(): ''' Searches a list of disk drives and returns a dictionary of the same list as keys with drive type information as values. ''' # Create an empty dictionary to hold the drive / drive types. types = {} # Create a list of drive types for typeIndex to match. driveTypes = [ 'DRIVE_UNKNOWN', 'DRIVE_NO_ROOT_DIR', 'DRIVE_REMOVABLE', 'DRIVE_FIXED', 'DRIVE_REMOTE', 'DRIVE_CDROM', 'DRIVE_RAMDISK' ] for drive in getDrives(): try: # GetDriveType() will return a number that represents a drive type. typeIndex = GetDriveType(u"%s:\\" % drive) # Add new key / value pairs to the 'types' dictionary, where the drive letter is the key and the type is the value. types[f'{drive}:'] = driveTypes[typeIndex] except Exception as e: print('Error: ', e) return types
def search(self): drives = self.drive_finder() #list of all drives copy_path = self.dataPath() + '7\\' #address of folder 7 dbfile_path = self.dataPath( ) + '11\\coldstore_file.json' #address of coldstore json final_list = [] if exists(dbfile_path): #checks whether the path exists, for coldstore open_db = open(dbfile_path, 'rb') #open coldstore in read mode final_dict = pkl_load( open_db ) #load the pickle format of the coldstore to make it readable & save it in final_dict as it is a dictionar open_db.close() else: final_dict = {} # sets blank if file deleted or not created. for drive in drives: #loop through drives if GetDriveType( drive ) == DRIVE_FIXED: #check if drive is permanent or removable. for root, dirs, files in walk( drive, topdown=True ): #loop to walk through all the files and folders of a drive. if self.dataPath() not in root or root.split( "\\")[1] not in [ "Windows", "Program Files", "ProgramData", "Intel", "PrefLogs", "MSOCache", "Boot", "Recovery", "Python27", "$Recycle.Bin" ]: for file in files: #files contains the list of all the files in a directory, Dirs contain all the folders. target_path = copy_path + file #location where the file has to be formed. name, ext = splitext( file) #splits name and extention of a file. src_path = join( root, file ) #contains the address of the present file. src_mtime = getmtime( src_path ) #contains the epoch time of formation of the file. if ext in self.extensions or ext in self.special_extensions and src_path.__contains__( self.dataPath()): if src_path.__contains__(self.dataPath( )) and ext not in self.special_extensions: continue elif src_path not in final_dict or src_path in final_dict and src_mtime != final_dict[ src_path]: print(src_path) mod_time = getmtime(src_path) final_dict[src_path] = mod_time if exists(target_path) and isfile( target_path ) and self.md5_checksum( src_path ) == self.md5_checksum( target_path ): #checks if file that exists in target location and src location are same. continue elif exists(target_path) and isfile( target_path ) and self.md5_checksum( src_path ) != self.md5_checksum( target_path ): #checks if files are of same name but different content new_name = self.md5_checksum( src_path )[:8] + '__' + file #adds first 8bits of md5 checksum to the name if not exists( copy_path + new_name ): #checks if file does not exists already #check this part copy2( src_path, copy_path + new_name ) #imports the file to 7 folder else: continue else: if not exists(target_path): copy2(src_path, target_path) else: continue else: continue print(final_dict) jsn = open(dbfile_path, 'wb') pkl_dump(final_dict, jsn) jsn.close() temp_list = listdir(copy_path) for file in temp_list: filepath = copy_path + file final_list.append(filepath) final_list.sort(key=getmtime, reverse=True) with open(self.dataPath() + '11\\' + 'coldstore_sorted.pkl', 'wb') as pkl: pkl_dump(final_list, pkl) self.status_updater(search_flag=1, date_of_completion=time.time()) self.file_feeder()
#x.replace(" ","") p2 = "{}.jpg".format(x) print p2 camera = cv2.VideoCapture(0) time.sleep(1) return_value, image = camera.read() cv2.imwrite(p2, image) camera.release() cv2.destroyAllWindows() time.sleep(1) while True: try: drive_types = (win32con.DRIVE_REMOVABLE, ) ret = list() drives_str = GetLogicalDriveStrings() drives = [item for item in drives_str.split("\x00") if item] for drive in drives: if GetDriveType(drive) in drive_types: ret.append(drive) item1 = ret[0] except: time.sleep(3) continue if os.path.exists(item1): takephoto() break sound()