No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Afficher les informations des disques (VBScript)

Le script suivant affiche une boîte de message pour chaque lecteur, avec quelques-unes de ses propriétés.

Fenêtre de résultat du script vbs qui affiche les stats du disque
  1. dim objFSO, colDrives, objDrive, aff, tempaff
  2. Set objFSO = CreateObject("Scripting.FileSystemObject")
  3. Set colDrives = objFSO.Drives
  4. For Each objDrive in colDrives
  5. if (objDrive.IsReady = true) then
  6. aff = "LETTRE DU DISQUE : " & objDrive.DriveLetter & vbcrlf
  7. aff = aff & "NOM DU DISQUE : " & objDrive.VolumeName & vbcrlf
  8. aff = aff & "NUMERO DE SERIE : " & objDrive.SerialNumber & vbcrlf
  9. aff = aff & "TYPE DE DISQUE : " & objDrive.DriveType & vbcrlf
  10. aff = aff & "SYSTEME DE FICHIERS : " & objDrive.FileSystem & vbcrlf
  11. aff = aff & "PATH : " & objDrive.Path & vbcrlf
  12. aff = aff & "DOSSIER RACINE : " & objDrive.RootFolder & vbcrlf
  13. aff = aff & "ESPACE TOTAL : " & objDrive.TotalSize & vbcrlf
  14. aff = aff & "ESPACE DISPONIBLE : " & objDrive.AvailableSpace & vbcrlf
  15. if (objDrive.ShareName <> "") then
  16. aff = aff & vbcrlf & "NOM DE PARTAGE : " & objDrive.ShareName
  17. end if
  18. MsgBox aff, vbInformation, "DiskInfo(brol)"
  19. else
  20. Wscript.Echo "DISQUE " & objDrive.DriveLetter & " NON PRET"
  21. end if
  22. Next
  23. Wscript.Echo colDrives.count & " DISQUES AFFICHES"

Procédure pas à pas

La procédure présentée ici permet de tester tous les objets de la collection drive (tous les lecteurs).

For Each objDrive in colDrives
.../
suite du code
/...
Next

Ensuite, nous devons tester la disponibilité du lecteur de disquettes et des lecteurs CD, etc.

Si le lecteur n'est pas disponible, un message est généré.

if (objDrive.IsReady = true) then
.../
suite du code
.../
else
Wscript.Echo "DISQUE " & objDrive.DriveLetter & " NON PRET"
end if

A présent, nous allons générer l'affichage des propriétés des disques qui sont disponibles. Pour cela, nous pouvons ajouter à chaque fois les données dans la variable aff que nous avons déclaré plus haut.

Nous pouvons remarquer l'emploi de vbcrlf, qui correspond à un retour chariot, pour une meilleure présentation.

aff = "LETTRE DU DISQUE : " & objDrive.DriveLetter & vbcrlf
aff = aff & "NOM DU DISQUE : " & objDrive.VolumeName & vbcrlf
aff = aff & "NUMERO DE SERIE : " & objDrive.SerialNumber & vbcrlf
aff = aff & "TYPE DE DISQUE : " & objDrive.DriveType & vbcrlf
aff = aff & "SYSTEME DE FICHIERS : " & objDrive.FileSystem & vbcrlf
aff = aff & "PATH : " & objDrive.Path & vbcrlf
aff = aff & "DOSSIER RACINE : " & objDrive.RootFolder & vbcrlf
aff = aff & "ESPACE TOTAL : " & objDrive.TotalSize & vbcrlf
aff = aff & "ESPACE DISPONIBLE : " & objDrive.AvailableSpace & vbcrlf

Nous pouvons en plus tester si le lecteur est un lecteur partagé. Dans le cas où il est partagé, nous allons afficher son nom de partage.

if (objDrive.ShareName <> "") then
aff = aff & vbcrlf & "NOM DE PARTAGE : " & objDrive.ShareName
end if

Il ne nous reste plus qu'à afficher le résultat de la variable.

Wscript.Echo aff

A la fin, nous pouvons afficher le nombre de disques trouvés, pour déclarer que le traitement est terminé.

Wscript.Echo colDrives.count & " DISQUES AFFICHES"

Afficher tous les disques en vbs sur une seule fenêtre

Voici un autre exemple, qui affiche le résultat sur une seule boîte (je n'affiche pas la totalité de l'image pour gagner un peu de place ;-) ).

Tous les disques durs sur une seule fenêtre en vbs
Cela peut poser un problème chez ceux qui utilisent la totalité des lettres de l'alphabet pour leurs connecteurs réseaux… :-)

Cet exemple présente de plus la particularité de faire appel à une fonction qui associera un nom au type de disque, au lieu d'une valeur.

  1. Sub DiskInfo
  2. Dim objFSO, colDrives, objDrive, aff, tempaff
  3. Set objFSO = CreateObject("Scripting.FileSystemObject")
  4. Set colDrives = objFSO.Drives
  5. For Each objDrive in colDrives
  6. if (objDrive.IsReady = true) then
  7. aff = aff & vbcrlf & vbcrlf & "LETTRE DU DISQUE : " & objDrive.DriveLetter & vbcrlf
  8. aff = aff & "NOM DU DISQUE : " & objDrive.VolumeName & vbcrlf
  9. aff = aff & "NUMERO DE SERIE : " & objDrive.SerialNumber & vbcrlf
  10. aff = aff & "TYPE DE DISQUE : " & DiskType (objDrive.DriveType) & vbcrlf
  11. aff = aff & "SYSTEME DE FICHIERS : " & objDrive.FileSystem & vbcrlf
  12. aff = aff & "PATH : " & objDrive.Path & vbcrlf
  13. aff = aff & "DOSSIER RACINE : " & objDrive.RootFolder & vbcrlf
  14. aff = aff & "ESPACE TOTAL : " & objDrive.TotalSize & vbcrlf
  15. aff = aff & "ESPACE DISPONIBLE : " & objDrive.AvailableSpace & vbcrlf
  16. if (objDrive.ShareName <> "") then
  17. aff = aff & vbcrlf & "NOM DE PARTAGE : " & objDrive.ShareName
  18. end if
  19. else
  20. aff = aff& vbcrlf& vbcrlf & "DISQUE " & objDrive.DriveLetter & " NON PRET" & vbcrlf
  21. aff = aff & "TYPE DE DISQUE : " & DiskType (objDrive.DriveType)
  22. end if
  23. Next
  24. Wscript.Echo colDrives.count & " DISQUES AFFICHES" & vbcrlf & aff
  25. End Sub
  26. Function DiskType (ByVal dType)
  27. Dim affType
  28. Select Case dType
  29. Case 0 : affType = "INCONNU"
  30. Case 1 : affType = "DISQUE AMOVIBLE"
  31. Case 2 : affType = "FIXE"
  32. Case 3 : affType = "DISTANT"
  33. Case 4 : affType = "CD-ROM"
  34. Case 5 : affType = "RAMDISK"
  35. End Select
  36. DiskType = affType
  37. End Function
  38. DiskInfo

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 11/06/2004, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/vbs-diskinfo.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.