Leggere il numero seriale dell' Hard-Disk
Questa funzione riesce a leggere il numero seriale, la label e il tipo di FAT di un disco (anche cd-rom) passato come parametro. Non funziona con il Floppy-Disk.
In un modulo BAS inserire:
Option Explicit
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 Const GETDI_SERIAL = 1
Public Const GETDI_LABEL = 2
Public Const GETDI_TYPE = 3
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
In un Form inserire un CommandButton ed il seguente codice:
Option Explicit
Private Sub Command1_Click()
Dim a As String, NomDrive As String
NomDrive = "C:\"
a = "Seriale = " & GetDriveInfo(NomDrive, GETDI_SERIAL)
a = a & " - " & "Tipo FAT : " & GetDriveInfo(NomDrive, GETDI_TYPE)
a = a & " - " & "Label : " & GetDriveInfo(NomDrive, GETDI_LABEL)
MsgBox a
End Sub
Testato su: Windows 98, Windows Me, Windows 2000 Professional