Newsgroup: it.comp.lang.visual-basic
Titolo: Qualcuno potrebbe darmi una mano, per favore ?

A tutti i NGisti:
vorrei sapere come posso creare un piccolo prog che mi permetta di mostrare lo spazio
libero e quello occupato dell'Hard Disk. Sì, solo questo, come se si cliccasse su
"Proprietà"
dell'Hard Disk.
Un grazie a tutti quelli che vorranno aiutarmi.
Ciao
Lorenzo
    ---------
 --O>> O>>--
--__M___----
       V
(
LO...@cyberia.arc.it
)

 Ciao
Original Tip Submitted By: Yatir Halevi
It is much easier than it seems to use the GetDiskFreeSpace Function, and it
is really useful. You can find the Capacity of a Drive, Free Space, Used
Space, Sectors per Cluster, Bytes per Sector, Number of Free Clusters, and
Total Number of Clusters.
Declare
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
Code
Then make 3 Text boxes: txtCapacity, txtFree and txtUsed. And make on
Command button: Command1.
Private Sub Command1_Click()
'The new-line and line feed command
 cr = Chr(13) & Chr(10)
 'Getting The Drive Letter
 drv = InputBox("Please type in your drive letter:" & cr & "For Example:
'c:\'")
 'Checking that it is correctly written
 If Right(drv, 1) <> "\" Then
  drv = drv & "\"
 End If
 'Getting the information: Sectors per Cluster,
 'Bytes per Sector, Number of Free Clusters,
 'and Total Number of Clusters
 result = GetDiskFreeSpace(drv, lspc, lbps, lnofc, ltnoc)
'Tells you if there was an error with the function
 If result = 0 Then MsgBox "There seems to be a problem!" & cr & "Check that
the drive you inserted exists," & cr & "and that you wrote it correctly!"
 'Calculates the Capacity of the Drive:
 'Sectors per Clusters * Bytes per Sector * Total
 'Number of Clusters
 txtCapacity.Text = lspc * lbps * ltnoc
 'Calculates the Free Space of the Drive:
 'Sectors per Clusters * Bytes per Sector * Number
'of Free Clusters
 txtFree.Text = lspc * lbps * lnofc
 'Calculates the Used Space of the Drive
 'Capacity - Free
 txtUsed.Text = Val(txtCapacity.Text) - Val(txtFree.Text)
 'Adds the word 'bytes' in the end
 txtCapacity.Text = txtCapacity.Text & " bytes"
 txtFree.Text = txtFree.Text & " bytes"
 txtUsed.Text = txtUsed.Text & " bytes"
End Sub
      Ciao
SimonenomiS


la GetDiskFreeSpace è ormai da buttare, dato che non supporta partizioni
maggiori di 2 Gb. Microsoft consiglia di usare GetDiskFreeSpaceEx. L'unico
problema che è esportata dal Kernel32 di WinNT, Win98, Win95 OSR 2 e basta,
ovvero nel Win95 "liscio" non la trovi (non supporta FAT32, per cui la
dimensione max di una partizione FAT è 2Gb.....). Per cui sei costretto a
distinguere la chiamata a runtime in funzione del sistema operativo sotto
cui il tuo processo gira.
hope this helps,
Lorenzo


Mi sa proprio che da VB ti devi accontentare della GetDiskFreeSpace, per una
semplice ragione che penso capirai subito appena vedrai la dichiarazione in
C:
BOOL GetDiskFreeSpaceEx(
  LPCTSTR lpDirectoryName,                 // pointer to the directory name
  PULARGE_INTEGER lpFreeBytesAvailableToCaller, // receives the number of
bytes on
                                                // disk available to the
caller
  PULARGE_INTEGER lpTotalNumberOfBytes,    // receives the number of bytes
on disk
  PULARGE_INTEGER lpTotalNumberOfFreeBytes // receives the free bytes on
disk
);
PULARGE_INTEGER è un intero unsigned a 64 bit.
L'intero più grande che VB per ora gestisce è il Long: 32 bits (che guarda
caso equivale a max 2Giga)
Comunque qui sotto c'è tutta la spiegazione data da M$.
Ti invito subito a leggere l'ultimo paragrafo che mette appunto in guardia
dal NON troncare i valori di ritorno a 32bit.
C'è anche una nota di come fare per sapere se il sistema supporta o no tale
funzione.
Ciao
----------------
Parameters
lpDirectoryName
Pointer to a null-terminated string that specifies a directory on the disk
of interest. This string can be a UNC name. If this parameter is a UNC name,
you must follow it with an additional backslash. For example, you would
specify \\MyServer\MyShare as \\MyServer\MyShare\.
If lpDirectoryName is NULL, the GetDiskFreeSpaceEx function obtains
information about the disk that contains the current directory.
Note that lpDirectoryName does not have to specify the root directory on a
disk. The function accepts any directory on the disk.
lpFreeBytesAvailableToCaller
Pointer to a variable to receive the total number of free bytes on the disk
that are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user quotas are in use, this value may be
less than the total number of free bytes on the disk.
lpTotalNumberOfBytes
Pointer to a variable to receive the total number of bytes on the disk that
are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user quotas are in use, this value may be
less than the total number of bytes on the disk.
lpTotalNumberOfFreeBytes
Pointer to a variable to receive the total number of free bytes on the disk.
This parameter can be NULL.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
Note that the values obtained by this function are of type ULARGE_INTEGER.
Be careful not to truncate these values to 32 bits.
Windows 95 OSR2: The GetDiskFreeSpaceEx function is available on Windows 95
systems beginning with OEM Service Release 2 (OSR2).
To determine whether GetDiskFreeSpaceEx is available, call the LoadLibrary
or LoadLibraryEx function to load the KERNEL32.DLL file, then call the
GetProcAddress function to obtain an address for GetDiskFreeSpaceEx. If
GetProcAddress fails, or if GetDiskFreeSpaceEx fails with the
ERROR_CALL_NOT_IMPLEMENTED code, use the GetDiskFreeSpace function instead
of GetDiskFreeSpaceEx.

 Lorenzo
Ti ringrazio tantissimo !!! Č proprio ciň che mi serviva !
E se volessi fare un grafico a torta, dove lo spazio usato č rosa e quello libero č
blu, come dovrei fare ?
Lo so che scoccio, ma sono alle prime armi, sai....
Ciao e grazie ancora !
Lorenzo