1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Option Explicit
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Private Sub Command1_Click()
Dim volbuff As String
volbuff = String(255, Chr$(0)) ' création d'un buffer pour les volumes
GetLogicalDriveStrings 255, volbuff ' exrraction des volumes présents
Dim i As Integer
For i = 1 To 100
If Left$(volbuff, InStr(1, volbuff, Chr$(0))) = Chr$(0) Then Exit For
' extraction des volumes & de leur nature
Text1.Text = Text1.Text & Left$(volbuff, InStr(1, volbuff, Chr$(0)) - 1) & " " & _
voyons_affichons(Left$(volbuff, InStr(1, volbuff, Chr$(0)) - 1)) & vbCrLf
volbuff = Right$(volbuff, Len(volbuff) - InStr(1, volbuff, Chr$(0)))
voyons_disque Left$(volbuff, InStr(1, volbuff, Chr$(0)) - 1)
Next i
End Sub
Private Function voyons_affichons(disque As String)
Dim toto As String
Select Case GetDriveType(disque)
Case 2
toto = " (disque ammovible)"
Case 3
toto = " (disque fixe)"
Case Is = 4
toto = " (disque distant)"
Case Is = 5
toto = " (Cd-Rom)"
Case Is = 6
toto = " (disque Ram)"
Case Else
toto = " (inexistant ou non reconnu)"
End Select
voyons_affichons = toto
End Function
Private Sub voyons_disque(disque As String)
Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Double
GetDiskFreeSpace disque, Sectors, Bytes, FreeC, TotalC ' extractions des informations/disque
If disque = "" Then Exit Sub
List1.AddItem " Path: " & disque
List1.AddItem " Sectors per Cluster:" & Str(Sectors)
List1.AddItem " Bytes per sector:" & Str(Bytes)
List1.AddItem " Number Of Free Clusters:" & Str(FreeC)
List1.AddItem " Total Number Of Clusters:" & Str(TotalC)
Dim totc As Double, frc As Double
totc = TotalC / 1000000000 'on veut afficher des gigaoctets
totc = totc * Sectors * Bytes
List1.AddItem "Nombre total d'octets : " & Str$(totc) & " gigaoctets"
frc = FreeC / 1000000000 'on veut afficher des gigaoctets
Freeb = frc * Sectors * Bytes
List1.AddItem " Nombre d'octets libres :" & Str$(Freeb) & " gigaoctets"
List1.AddItem ""
List1.AddItem "=================="
List1.AddItem ""
End Sub |
Partager