API call for hard drive serial number
Quote:
>Does anyone know the VB syntax for the API call to read the serial number
from
>the boot hard drive?, how about the CPU serial number?
>Thanks
>Mark Sale
Disk serial number, try this code:
Private Function getDiskSerialNumber() as long
Dim dummy1 As OFSTRUCT, dummy2 As Long
dim res As Long, Handle As Long
Dim vars As BY_HANDLE_FILE_INFORMATION
dim SerNumber As Long, sysDir As String
sysDir = Dir("*.*") ' or dir(Environ("SystemDrive") & "\*.*") if you are
using nt
Handle = OpenFile(sysDir, dummy1, dummy2)
res = GetFileInformationByHandle(Handle, vars)
SerNumber = Abs(vars.dwVolumeSerialNumber)
res = CloseHandle(Handle)
'now u have the serial number of the disk.
getDiskSerialNumber=SerNumber
end function
' paste this code on a BAS module or in the declarations section:
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(128) As Byte
End Type
Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As
Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String,
lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long