Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

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

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2004 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/vbs-diskinfo.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.