API call for hard drive serial number 
Author Message
 API call for hard drive serial number

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




Tue, 12 Sep 2000 03:00:00 GMT  
 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



Tue, 12 Sep 2000 03:00:00 GMT  
 API call for hard drive serial number

Did you want the C: Drive volume serial number or the physical hard disk
embedded serial number?



Tue, 12 Sep 2000 03:00:00 GMT  
 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



try this:

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



Tue, 12 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Hard Drive Serial Number/Total Drive Size

2. hard drive serial number

3. Reading the Hard Drives Serial Number

4. Hard Drive Serial Number

5. Hard Drive Volume Serial Number

6. Reading the hard drive's serial number

7. Hard drive serial number

8. Getting Hard Drive Serial number

9. How can I get the serial (or other) number of my hard drive through VB

10. How can I get the serial (or other) number of my hard drive through VB

11. Hard Drive Serial Numbers

12. Hard Drive Serial Numbers

 

 
Powered by phpBB® Forum Software