Dim drives() As IO.DriveInfo = IO.DriveInfo.GetDrives For Each drv As IO.DriveInfo In drives If drv.IsReady Then If drv.DriveType <> IO.DriveType.Removable Then '... End If End If Next
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Dim MyArrayDrives, MyArraySpaces, strList Set MyArrayDrives = CreateObject("System.Collections.ArrayList") Set MyArraySpaces = CreateObject("System.Collections.ArrayList") MsgBox CheckDrives(strList) Set MyArrayDrives = Nothing Set MyArraySpaces = Nothing WScript.Quit Function CheckDrives(strList) Dim objFso, strDrive, strItem, strResult, i Set objFso = CreateObject("Scripting.FileSystemObject") For Each strDrive In objFso.Drives If strDrive.IsReady And strDrive.DriveType = 2 Then MyArrayDrives.Add "DriveLetter " & strDrive.DriveLetter & ":" &_ vbTab & "=> AvailableSpace: " &_ FormatNumber(strDrive.AvailableSpace/1024/1024, 0) & " Mo" MyArraySpaces.Add Space(1) & FormatNumber(strDrive.AvailableSpace/1024/1024, 0) & " Mo" strList = strList &vbLf&_ "DriveLetter " & strDrive.DriveLetter & ":" &vbTab&_ "=> AvailableSpace: " &_ FormatNumber(strDrive.AvailableSpace/1024/1024, 0) & " Mo" End If Next MyArraySpaces.Sort MyArraySpaces.Reverse For Each strItem in MyArrayDrives If InStr(1, strItem, MyArraySpaces(0)) Then strResult = strItem : Exit For Next CheckDrives = strResult &vbCrLf&vbCrLf&vbCrLf& "List Drives" &vbLf& strList Set objFso = Nothing End Function
Option Explicit Dim MyArrayDrives, MyArraySpaces, strList Set MyArrayDrives = CreateObject("System.Collections.ArrayList") Set MyArraySpaces = CreateObject("System.Collections.ArrayList") MsgBox CheckDrives(strList) Set MyArrayDrives = Nothing Set MyArraySpaces = Nothing WScript.Quit Function CheckDrives(strList) Dim objFso Dim strDrive, strDriveLetter, strDriveSpace, strItem, strResult Set objFso = CreateObject("Scripting.FileSystemObject") For Each strDrive In objFso.Drives If strDrive.IsReady And strDrive.DriveType = 2 Then If strDrive.FileSystem = "NTFS" Then strDriveLetter = "DriveLetter " & strDrive.DriveLetter & ":" strDriveSpace = "=> AvailableSpace: " &_ FormatNumber(strDrive.AvailableSpace/1024/1024, 0) & " Mo" MyArrayDrives.Add strDriveLetter & vbTab & strDriveSpace MyArraySpaces.Add strDriveSpace strList = strList &vbLf&_ strDriveLetter &vbTab& strDriveSpace End If End If Next MyArraySpaces.Sort MyArraySpaces.Reverse For Each strItem in MyArrayDrives If InStr(strItem, MyArraySpaces(0)) Then strResult = strItem : Exit For Next CheckDrives = strResult &vbCrLf&vbCrLf&vbCrLf& "List Drives" &vbLf& strList Set objFso = Nothing End Function
'Find USB Stick Set dicUSBDrives = GetUSBDrives '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- If dicUSBDrives.Count = 0 Then MsgBox "Pas trouvé de clé USB!",48,"Chercher clé USB connectée" Else MsgBox "Trouvé une clé USB:",64,"Chercher clé USB connectée" For Each strUSBDrive In dicUSBDrives MsgBox "Emplacement: " & strUSBDrive & "",64,"Chercher clé USB connectée" Target = strUSBDrive & "\MyDocuments" Next End If '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- Function GetUSBDrives ' Populate a dictionary object with USB drive letters Set dicUSBList = CreateObject("Scripting.Dictionary") dicUSBList.CompareMode = vbTextCompare strComputer = "." Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") Set colDiskDrives = objWMI.ExecQuery ("Select DeviceID from Win32_DiskDrive WHERE InterfaceType='USB'") For Each objDiskDrive In colDiskDrives strDeviceID = objDiskDrive.DeviceID strEscapedDeviceID = Replace(strDeviceID, "", "\") Set colDiskPartitions = objWMI.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strEscapedDeviceID & """} WHERE " _ & "AssocClass = Win32_DiskDriveToDiskPartition") For Each objDiskPartition In colDiskPartitions Set colLogicalDisks = objWMI.ExecQuery ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _ objDiskPartition.DeviceID & """} WHERE " & _ "AssocClass = Win32_LogicalDiskToPartition") For Each objLogicalDisk In colLogicalDisks dicUSBList.Add objLogicalDisk.DeviceID, "" Next Next Next Set GetUSBDrives = dicUSBList End Function