|
Programmazione LEGGERE IL SERIALE DELL'HARD DISKAutore: Fabio Pacioni Per
leggere il seriale del disco rigido è necessario ricorrere
alla funzione Incollare il seguente codice nella sezione generale del Form Private Declare Function GetVolumeInformation Lib "kernel32" Alias_ "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal_ lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long,_ lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long,_ lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String,_ ByVal nFileSystemNameSize As Long) As Long Public Function GetSeriale(strUnit As String) 'restituisce il seriale dell'unita specificata Dim Seriale As Long, strLabel As String, strType As String, outVal As Long outVal = GetVolumeInformation(strUnit, strLabel, Len(strLabel),_ Seriale, 0, 0, strType, Len(strType)) If outVal = 1 Then GetSeriale = CStr(Seriale) Else GetSeriale = 0 End If End Function Public Function GetEtichetta(strUnit As String) 'restituisce l'etichetta dell'unita specificata Dim Seriale As Long, strLabel As String, strType As String, outVal As Long strLabel = Space(256) outVal = GetVolumeInformation(strUnit, strLabel, Len(strLabel),_ Seriale, 0, 0, strType, Len(strType)) If outVal = 1 Then strLabel = Trim(strLabel) GetEtichetta = Left$(strLabel, Len(strLabel) - 1) If GetEtichetta = "" Then GetEtichetta = "Il volume non ha etichetta" Else GetEtichetta = 0 End If End Function Public Function GetTypeFAT(strUnit As String) 'restituisce il tipo di FAT dell'unita specificata Dim Seriale As Long, strLabel As String, strType As String, outVal As Long strType = Space(256) outVal = GetVolumeInformation(strUnit, strLabel, Len(strLabel),_ Seriale, 0, 0, strType, Len(strType)) If outVal = 1 Then strType = Trim(strType) GetTypeFAT = Left$(strType, Len(strType) - 1) Else GetTypeFAT = 0 End If End Function
Private Sub Command1_Click() ' le funzioni ritornano 0 se ci sono errori(ad esempio se 'il disco non è presente nell'unità Text1.Text = "Seriale : " & GetSeriale("C:\") Text2.Text = "Tipo FAT : " & GetTypeFAT("C:\") Text3.Text = "Label : " & GetEtichetta("C:\") End Sub |