Drivelistbox : que les disques durs

scoder Messages postés 140 Date d'inscription dimanche 18 avril 2004 Statut Membre Dernière intervention 20 mars 2006 - 12 juin 2004 à 18:04
scoder Messages postés 140 Date d'inscription dimanche 18 avril 2004 Statut Membre Dernière intervention 20 mars 2006 - 12 juin 2004 à 22:45
Bonjour,

j'ai plusieurs serveurs et un poste à partir duquel je les gère. malheureusement je suis obligé de surveiller manuellement l'espace disque libre sur ceux ci, afin qu'ils ne soient pas saturés. J'ai donc pensé faire une appli qui m'enverrai un msg lorsque l'espace libre serait trop faible.
j'ai un drivelistbox sur mon form, et j'aimerai savoir comment faire pour récupérer uniquement les infos de mes disques durs, et non des lecteurs cd qui apparaîssent aussi dans le drivelistbox

quelqu'un sait comment faire ça?

merci

4 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 78
12 juin 2004 à 19:25
Salut scoder
Un peu de recherche sur vbfrance avec "drive type" t'aurait répondu avec notemment cette source
Vala
Jack
0
scoder Messages postés 140 Date d'inscription dimanche 18 avril 2004 Statut Membre Dernière intervention 20 mars 2006
12 juin 2004 à 19:35
Merci Jack ;)
0
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 20
12 juin 2004 à 20:17
Bonsoir scoder,

un tit bout de code qui marche, pour tester, tu colles ça ds une form :

Private Declare Function GetDiskFreeSpaceEx _
Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
( _
ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency _
) As Long

Private Sub Form_Load()
' dans projet/références, cocher "Microsoft Scripting Runtime"
Dim fso As FileSystemObject
Dim Drv As Drive, DrvName As String
Dim d As Drive
Dim dc As Drives
Dim st As String
Dim TotalBytes, FreeBytes As Currency
Dim Espace_Libre As String
Dim Espace_Total As String
Dim Pourcentage_Libre As Long

Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives

For Each d In dc

Set Drv = fso.GetDrive(Mid(d, 1, 2))

If Drv.DriveType = Remote Then

DrvName = Drv.Path & ""

st = DrvName & " " & Drv.ShareName

Pourcentage_Libre = 0
Espace_Libre = ""
Espace_Total = ""

If Drv.IsReady Then

GetDiskFreeSpaceEx Drv & "", 0, TotalBytes, FreeBytes

Pourcentage_Libre = Int(FreeBytes * 10000 / (TotalBytes * 10000) * 100)

If FreeBytes * 10000 > 1024 ^ 3 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024 ^ 3), -1) & " Go"
Else
If FreeBytes * 10000 > 1024 ^ 2 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024 ^ 2), -1) & " Mo"
Else
If FreeBytes * 10000 > 1024 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024), -1) & " Ko"
End If
End If
End If

If TotalBytes * 10000 > 1024 ^ 3 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024 ^ 3), -1) & " Go"
Else
If TotalBytes * 10000 > 1024 ^ 2 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024 ^ 2), -1) & " Mo"
Else
If TotalBytes * 10000 > 1024 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024), -1) & " Ko"
End If
End If
End If
End If

If Pourcentage_Libre <> 0 Then
st = st & " - Libre " & Espace_Libre & " (" & Pourcentage_Libre & "%)"
st = st & " - Total " & Espace_Total
End If

End If

Next

MsgBox st

Set fso = Nothing

End Sub

Cordialement

CanisLupus
0
scoder Messages postés 140 Date d'inscription dimanche 18 avril 2004 Statut Membre Dernière intervention 20 mars 2006
12 juin 2004 à 22:45
Merci à toi CanisLupus ;)
0
Rejoignez-nous