Le code récent d'Ar-S sur les lettres disponibles des lecteurs m'a rappelé un vieux code que je m'étais confectionné pour lister tous les volumes montés et récupérer certaines informations les concernant :
Code : Tout sélectionner
; Dernière version testée avec PB6.10 b7 : Windows uniquement
EnableExplicit
; ╔═════════════════════════════════════════════════════════════════════════════╗
; ║ STRUCTURES - ENUMERATIONS - CONSTANTES - MACROS - MAPS - VARIABLES GLOBALES ║
; ╚═════════════════════════════════════════════════════════════════════════════╝
;{ ════ STRUCTURES ════
;- ════ STRUCTURES ════
Structure STORAGE_PROPERTY_QUERY ;{
PropertyId.l;STORAGE_PROPERTY_ID
QueryType.l;STORAGE_QUERY_TYPE
AdditionalParameters.l
EndStructure ;}
Structure STORAGE_DEVICE_DESCRIPTOR ;{
Version.l
Size.l ; Long
DeviceType.b ; Byte
DeviceTypeModifier.b ; Byte
RemovableMedia.b ; Byte
CommandQueueing.b ; Byte
VendorIdOffset.l ; Long
ProductIdOffset.l ; Long
ProductRevisionOffset.l ; Long
SerialNumberOffset.l ; Long
BusType.w ; Integer
RawPropertiesLength.l ; Long
RawDeviceProperties.b ; Byte
Reserved.b[1024]
EndStructure ;}-
Structure INFOSVOLUMES ;{
Volume.s
NomVolume.s
TypeVolume.s
TypeBus.s
Amovible.a
IDProduit.s
RevProduit.s
IDFabricant.s
NoSerie.s
EspaceTotal.q
EspaceUtilise.q
EspaceLibre.q
EndStructure ;}-
;}
;{ ════ ENUMERATIONS ════
;- ════ ENUMERATIONS ════
Enumeration TypesBus ;{
#TypeBus_Inconnu
#TypeBus_SCSI
#TypeBus_ATAPI
#TypeBus_ATA
#TypeBus_IEEE1394
#TypeBus_SSA
#TypeBus_FB ; Canal fibre
#TypeBus_USB
#TypeBus_RAID
#TypeBus_ISCSI
#TypeBus_SAS
#TypeBus_SATA
#TypeBus_SD ; Secure digital
#TypeBus_MMC ; Multimedia Card
#TypeBus_Reserve ; This value is reserved For system use
#TypeBus_FBV ; File Backed Virtual
#TypeBus_SS ; Espaces de stockages
#TypeBus_NVME
EndEnumeration ;}
;}
;{ ════ CONSTANTES ════
;- ════ CONSTANTES ════
#IOCTL_STORAGE_QUERY_PROPERTY=$2D1400
;}
;-══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
; ╔════════════╗
; ║ PROCEDURES ║
; ╚════════════╝
; ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Procedure Pc_Lecture_InfosVolumes(List ArgInfosVolumes.INFOSVOLUMES())
Protected.STORAGE_PROPERTY_QUERY STORAGEPROPERTYQUERY
Protected.STORAGE_DEVICE_DESCRIPTOR STORAGEDEVICEDESCRIPTOR
Protected hDrive
Protected.l Resultat,NbOctets
Protected.a NbVolumes,Compteur,TypeVolume
Protected.u Compteur2
Protected.s ChaineVolume
ClearList(ArgInfosVolumes())
For Compteur=1 To 26 ; Boucle pour les 26 lettres de lecteurs autorisées (Compteur=1 -> "A", Compteur=2 -> "B", Compteur=3 -> "C", etc.)
ChaineVolume="\\.\"+Chr(64+Compteur)+":"
hDrive=CreateFile_(ChaineVolume,0,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)
If hDrive<>-1
STORAGEPROPERTYQUERY.STORAGE_PROPERTY_QUERY
STORAGEDEVICEDESCRIPTOR.STORAGE_DEVICE_DESCRIPTOR
For Compteur2=0 To 1023
STORAGEDEVICEDESCRIPTOR\Reserved[Compteur2]=0
Next
Resultat=DeviceIoControl_(hDrive,#IOCTL_STORAGE_QUERY_PROPERTY,STORAGEPROPERTYQUERY,SizeOf(STORAGEPROPERTYQUERY),@STORAGEDEVICEDESCRIPTOR,SizeOf(STORAGEDEVICEDESCRIPTOR),@NbOctets,0)
If Resultat
AddElement(ArgInfosVolumes())
With ArgInfosVolumes()
\Volume=Chr(64+Compteur)+":\"
\NomVolume=Space(#MAX_PATH)
GetVolumeInformation_(@\Volume,@\NomVolume,#MAX_PATH+1,0,0,0,0,0)
\NomVolume=Trim(\NomVolume)
TypeVolume=GetDriveType_(@\Volume)
Select TypeVolume
Case #DRIVE_UNKNOWN:\TypeVolume="Type de disque inconnu"
Case #DRIVE_NO_ROOT_DIR:\TypeVolume="Disque non monté"
Case #DRIVE_REMOVABLE:\TypeVolume="Disque amovible"
Case #DRIVE_FIXED:\TypeVolume="Disque fixe"
Case #DRIVE_REMOTE:\TypeVolume="Disque réseau"
Case #DRIVE_CDROM:\TypeVolume="Disque CD-ROM"
Case #DRIVE_RAMDISK:\TypeVolume="Disque RAM"
EndSelect
Select(STORAGEDEVICEDESCRIPTOR\Bustype)
Case #TypeBus_Inconnu:\TypeBus="Type de volume inconnu"
Case #TypeBus_SCSI:\TypeBus="Volume SCSI"
Case #TypeBus_ATAPI:\TypeBus="Volume ATAPI"
Case #TypeBus_ATA:\TypeBus="Volume ATA"
Case #TypeBus_IEEE1394:\TypeBus="Volume IEEE 1394"
Case #TypeBus_SSA:\TypeBus="Volume SSA"
Case #TypeBus_FB:\TypeBus="Volume Canal fibre"
Case #TypeBus_USB:\TypeBus="Volume USB"
Case #TypeBus_RAID:\TypeBus="Volume RAID"
Case #TypeBus_ISCSI:\TypeBus="Volume ISCSI"
Case #TypeBus_SAS:\TypeBus="Volume SAS"
Case #TypeBus_SATA:\TypeBus="Volume SATA"
Case #TypeBus_SD:\TypeBus="Volume Secure digital"
Case #TypeBus_MMC:\TypeBus="Volume Carte multimédia"
Case #TypeBus_Reserve:\TypeBus="Type de bus reservé"
Case #TypeBus_FBV:\TypeBus="Volume virtuel de sauvegarde"
Case #TypeBus_SS:\TypeBus="Volume espace de stockage"
Case #TypeBus_NVME:\TypeBus="Volume SSD NVM Express"
Default:\TypeBus="Type de volume non recensé"
EndSelect
If STORAGEDEVICEDESCRIPTOR\RemovableMedia
\Amovible=#True
EndIf
If STORAGEDEVICEDESCRIPTOR\ProductIdOffset>0
\IDProduit=Trim(PeekS(@STORAGEDEVICEDESCRIPTOR+STORAGEDEVICEDESCRIPTOR\ProductIdOffset,-1,#PB_Ascii))
EndIf
If STORAGEDEVICEDESCRIPTOR\ProductRevisionOffset>0
\RevProduit=Trim(PeekS(@STORAGEDEVICEDESCRIPTOR+ STORAGEDEVICEDESCRIPTOR\ProductRevisionOffset,-1,#PB_Ascii))
EndIf
If STORAGEDEVICEDESCRIPTOR\VendorIdOffset >0
\IDFabricant=Trim(PeekS(@STORAGEDEVICEDESCRIPTOR+ STORAGEDEVICEDESCRIPTOR\VendorIdOffset,-1,#PB_Ascii))
EndIf
If STORAGEDEVICEDESCRIPTOR\SerialNumberOffset >0
\NoSerie=Trim(PeekS(@STORAGEDEVICEDESCRIPTOR+ STORAGEDEVICEDESCRIPTOR\SerialNumberOffset,-1,#PB_Ascii))
EndIf
If GetDiskFreeSpaceEx_(\Volume,@\EspaceLibre,@\EspaceTotal,0)
\EspaceUtilise=\EspaceTotal-\EspaceLibre
EndIf
EndWith
Else
EndIf
EndIf
CloseHandle_(hDrive)
Next
ResetList(ArgInfosVolumes())
EndProcedure
;-══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
; ╔══════╗
; ║ TEST ║
; ╚══════╝
; ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
CompilerIf #PB_Compiler_IsMainFile
Define.s Sortie
Define.a CouleurTexte=6
NewList InfosVolumes.INFOSVOLUMES()
Pc_Lecture_InfosVolumes(InfosVolumes())
Macro Mc_Affichage_LigneConsole(ArgLibelle,ArgValeur)
Print(ArgLibelle)
ConsoleColor(CouleurTexte,0)
PrintN(ArgValeur)
ConsoleColor(7,0)
EndMacro
OpenConsole()
PrintN("Liste des volumes :")
If ListSize(InfosVolumes())
PrintN("══════════════════════════════════════════════════")
ResetList(InfosVolumes())
While NextElement(InfosVolumes())
With InfosVolumes()
Print("Le volume ")
ConsoleColor(9,0)
Print(\Volume)
ConsoleColor(7,0)
Mc_Affichage_LigneConsole(": est un ",\TypeBus)
If \NomVolume:Mc_Affichage_LigneConsole(" Nom volume = ",\NomVolume):EndIf
If \TypeVolume:Mc_Affichage_LigneConsole(" Type de disque = ",\TypeVolume):EndIf
If \IDProduit:Mc_Affichage_LigneConsole(" ID produit = ",\IDProduit):EndIf
If \RevProduit:Mc_Affichage_LigneConsole(" Révision produit = ",\RevProduit):EndIf
If \IDFabricant:Mc_Affichage_LigneConsole(" ID fabricant = ",\IDFabricant):EndIf
If \NoSerie:Mc_Affichage_LigneConsole(" N° de série = ",\NoSerie):EndIf
Mc_Affichage_LigneConsole(" Espace total = ",FormatNumber(\EspaceTotal,0,""," "))
Mc_Affichage_LigneConsole(" Espace utilisé = ",FormatNumber(\EspaceUtilise,0,""," "))
Mc_Affichage_LigneConsole(" Espace libre = ",FormatNumber(\EspaceLibre,0,""," "))
EndWith
PrintN("══════════════════════════════════════════════════")
Wend
EndIf
Sortie=Input()
CloseConsole()
CompilerEndIf
Il est facilement adaptable pour ne récupérer les infos que d'un seul volume.
Il suffit de supprimer/adapter les lignes 87 et 88 du code et de virer toutes notions de List()
Edit du 11/03/24 : Quelques modifications/corrections typographiques dans le code qui ne changent absolument en rien l'exécution et le résultat de celui initialement posté