Python win32api.GetVolumeInformation() Examples

The following are 5 code examples of win32api.GetVolumeInformation(). 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 win32api , or try the search function .
Example #1
Source File: LauncherBase.py    From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def MakeNTFSFilesGlobalWriteable(self, pathToSet=None):
        if not self.WIN32:
            return
        import win32api
        if pathToSet == None:
            pathToSet = self.getInstallDir()
        else:
            pathToSet = pathToSet.cStr() + '*'
        DrivePath = pathToSet[0:3]
        try:
            volname, volsernum, maxfilenamlen, sysflags, filesystemtype = win32api.GetVolumeInformation(DrivePath)
        except:
            return

        if self.win32con_FILE_PERSISTENT_ACLS & sysflags:
            self.notify.info('NTFS detected, making files global writeable\n')
            win32dir = win32api.GetWindowsDirectory()
            cmdLine = win32dir + '\\system32\\cacls.exe "' + pathToSet + '" /T /E /C /G Everyone:F > nul'
            os.system(cmdLine)
        return 
Example #2
Source File: windows-privesc-check.py    From WHP with Do What The F*ck You Want To Public License 5 votes vote down vote up
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 #3
Source File: windowsprivcheck.py    From LHF with GNU General Public License v3.0 5 votes vote down vote up
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: platform.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def get_sparse_files_support(path):
    supported = False

    if os.name == 'nt':
        drive, path = os.path.splitdrive(os.path.abspath(path))
        if len(drive) > 0: # might be a network path
            if drive[-1] != '\\':
                drive += '\\'
            volumename, serialnumber, maxpath, fsflags, fs_name = win32api.GetVolumeInformation(drive)
            if fsflags & FILE_SUPPORTS_SPARSE_FILES:
                supported = True

    return supported

# is there a linux max path? 
Example #5
Source File: platform.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def get_max_filesize(path):
    fs_name = None
    # optimistic if we can't tell
    max_filesize = 2**64

    if os.name == 'nt':
        drive, path = os.path.splitdrive(os.path.abspath(path))
        if len(drive) > 0: # might be a network path
            if drive[-1] != '\\':
                drive += '\\'
            volumename, serialnumber, maxpath, fsflags, fs_name = win32api.GetVolumeInformation(drive)
            if fs_name == "FAT32":
                max_filesize = 2**32 - 1
            elif (fs_name == "FAT" or
                  fs_name == "FAT16"):
                # information on this varies, so I chose the description from
                # MS: http://support.microsoft.com/kb/q118335/
                # which happens to also be the most conservative.
                max_clusters = 2**16 - 11
                max_cluster_size = 2**15
                max_filesize = max_clusters * max_cluster_size
    else:
        path = os.path.realpath(path)
        # not implemented yet
        #fsname = crawl_path_for_mount_entry(path)

    return fs_name, max_filesize