Python win32file.GetDriveType() Examples
The following are 9
code examples of win32file.GetDriveType().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32file
, or try the search function
.
Example #1
Source File: win32.py From multibootusb with GNU General Public License v2.0 | 5 votes |
def findAvailableDrives(): return [(d, win32file.GetDriveType(d)) for d in win32api.GetLogicalDriveStrings().rstrip('\0').split('\0')]
Example #2
Source File: win32.py From multibootusb with GNU General Public License v2.0 | 5 votes |
def findVolumeGuids(): DiskExtent = collections.namedtuple( 'DiskExtent', ['DiskNumber', 'StartingOffset', 'ExtentLength']) Volume = collections.namedtuple( 'Volume', ['Guid', 'MediaType', 'DosDevice', 'Extents']) found = [] h, guid = FindFirstVolume() while h and guid: #print (guid) #print (guid, win32file.GetDriveType(guid), # win32file.QueryDosDevice(guid[4:-1])) hVolume = win32file.CreateFile( guid[:-1], win32con.GENERIC_READ, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None) extents = [] driveType = win32file.GetDriveType(guid) if driveType in [win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED]: x = win32file.DeviceIoControl( hVolume, winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, None, 512, None) instream = io.BytesIO(x) numRecords = struct.unpack('<q', instream.read(8))[0] fmt = '<qqq' sz = struct.calcsize(fmt) while 1: b = instream.read(sz) if len(b) < sz: break rec = struct.unpack(fmt, b) extents.append( DiskExtent(*rec) ) vinfo = Volume(guid, driveType, win32file.QueryDosDevice(guid[4:-1]), extents) found.append(vinfo) guid = FindNextVolume(h) return found
Example #3
Source File: windows-privesc-check.py From WHP with Do What The F*ck You Want To Public License | 5 votes |
def check_drives(): for drive in win32api.GetLogicalDriveStrings().split("\x00"): sys.stdout.write(".") type = win32file.GetDriveType(drive) if type == win32con.DRIVE_FIXED: fs = win32api.GetVolumeInformation(drive)[4] if fs == 'NTFS': warning = "" weak_perms = check_weak_write_perms(drive, 'directory') if weak_perms: # print "Weak permissions on drive root %s:" % drive # print_weak_perms('directory', weak_perms) sys.stdout.write(".") save_issue("WPC010", "writable_drive_root", weak_perms) elif fs == 'FAT': save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT does not support file permissions)" ) sys.stdout.write("!") elif fs == 'FAT32': save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT32 does not support file permissions)" ) sys.stdout.write("!") else: warning = " (not NTFS - might be insecure)" save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (Not NTFS - might not be secure)" ) sys.stdout.write("!") # print "Fixed drive %s has %s filesystem%s" % (drive, fs, warning) print
Example #4
Source File: utils.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
def get_local_drives(): """Returns a list containing letters from local drives""" drive_list = win32api.GetLogicalDriveStrings() drive_list = drive_list.split("\x00")[0:-1] # the last element is "" list_local_drives = [] for letter in drive_list: if win32file.GetDriveType(letter) == win32file.DRIVE_FIXED: list_local_drives.append(letter) return list_local_drives
Example #5
Source File: utils.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
def get_removable_drives(): """Returns a list containing letters from removable drives""" drive_list = win32api.GetLogicalDriveStrings() drive_list = drive_list.split("\x00")[0:-1] # the last element is "" list_removable_drives = [] for letter in drive_list: if win32file.GetDriveType(letter) == win32file.DRIVE_REMOVABLE: list_removable_drives.append(letter) return list_removable_drives
Example #6
Source File: windowsprivcheck.py From LHF with GNU General Public License v3.0 | 5 votes |
def check_drives(): for drive in win32api.GetLogicalDriveStrings().split("\x00"): sys.stdout.write(".") type = win32file.GetDriveType(drive) if type == win32con.DRIVE_FIXED: fs = win32api.GetVolumeInformation(drive)[4] if fs == 'NTFS': warning = "" weak_perms = check_weak_write_perms(drive, 'directory') if weak_perms: # print "Weak permissions on drive root %s:" % drive # print_weak_perms('directory', weak_perms) sys.stdout.write(".") save_issue("WPC010", "writable_drive_root", weak_perms) elif fs == 'FAT': save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT does not support file permissions)" ) sys.stdout.write("!") elif fs == 'FAT32': save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT32 does not support file permissions)" ) sys.stdout.write("!") else: warning = " (not NTFS - might be insecure)" save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (Not NTFS - might not be secure)" ) sys.stdout.write("!") # print "Fixed drive %s has %s filesystem%s" % (drive, fs, warning) print
Example #7
Source File: getfiles_hash.py From certitude with GNU General Public License v2.0 | 5 votes |
def getFilesHash(): ret = [] # List logical drives drives = win32api.GetLogicalDriveStrings().split('\x00') drives.pop() # Only get local dries drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ] # List files for drive in drives: hashRec(drive)
Example #8
Source File: getfiles.py From certitude with GNU General Public License v2.0 | 5 votes |
def getFiles(): ret = [] # List logical drives drives = win32api.GetLogicalDriveStrings().split('\x00') drives.pop() # Only get local dries drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ] # List files for drive in drives: print os.popen('dir /s /b '+drive).read()
Example #9
Source File: Base.py From Crypter with GNU General Public License v3.0 | 5 votes |
def is_optical_drive(self, drive_letter): ''' @summary: Checks if the specified drive letter is an optical drive @param drive_letter: The letter of the drive to check @return: True if drive is an optical drive, otherwise false ''' if win32file.GetDriveType('%s:' % drive_letter) == win32file.DRIVE_CDROM: return True else: return False