Computer - Legge Il Numero Seriale Dell'Hard Disk




windows # Legge il numero seriale dell' HD
Questa funzione legge il numero seriale, la label e il tipo di FAT di un HD e Cd-Rom
passato come parametro. Non funziona con il Floppy-Disk.
COSTANTI
Public Const GETDI_SERIAL = 1
Public Const GETDI_LABEL = 2
Public Const GETDI_TYPE = 3
DICHIARAZIONE FUNZIONI API
' funzioni richieste.


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
CODICE FUNZIONI PUBBLICHE
Public Function GetDriveInfo(strDrive As String, iType As Integer)

Dim SerialNum As Long
Dim strLabel As String
Dim strType As String

Dim lRetVal As Long

strLabel = Space(256)
strType = Space(256)

lRetVal = GetVolumeInformation(strDrive, strLabel, Len(strLabel), SerialNum, 0, 0, strType, Len(strType))

Select Case iType
Case Is = 1
GetDriveInfo = CStr(SerialNum)
Case Is = 2
strLabel = Trim(strLabel)
GetDriveInfo = Left$(strLabel, Len(strLabel) - 1)
Case Is = 3
strType = Trim(strType)
GetDriveInfo = Left$(strType, Len(strType) - 1)
End Select
End Function


CODICE DEL FORM
Creare una Form con un controllo CommandButton di nome 'Command1'
Inserire questo codice:
Private Sub Command1_Click()
Dim a As String

a = "Seriale = " & GetDriveInfo("C:\", GETDI_SERIAL)
a = a & " - " & "Tipo FAT : " & GetDriveInfo("C:\", GETDI_TYPE)
a = a & " - " & "Label : " & GetDriveInfo("C:\", GETDI_LABEL)

MsgBox a
End Sub











( computerleggeilnumeroserialedell'harddisk.html )- by Paolo Puglisi - Modifica del 17/12/2023