Private Declare Function apiGetVolumeInformation 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
Private Const MAX_PATH = 260
Function fSerialNumber(strDriveLetter As String) As String
' Function to return the serial number for a hard drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The serial number for the drive, formatted as "xxxx-xxxx"
Dim lngReturn As Long, lngDummy1 As Long, lngDummy2 As Long, lngSerial As Long
Dim strDummy1 As String, strDummy2 As String, strSerial As String
strDummy1 = Space(MAX_PATH)
strDummy2 = Space(MAX_PATH)
lngReturn = apiGetVolumeInformation(strDriveLetter, strDummy1, Len(strDummy1), lngSerial, lngDummy1, lngDummy2, strDummy2, Len(strDummy2))
strSerial = Trim(Hex(lngSerial))
strSerial = String(8 - Len(strSerial), "0" & strSerial
strSerial = Left(strSerial, 4) & "-" & Right(strSerial, 4)
fSerialNumber = strSerial
End Function
Good luck! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
Sub ShowDriveInfo(drvpath)
Dim fs, d, t
Set fs = CreateObject("Scripting.FileSystemObject"
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
s = "Drive " & d.DriveLetter & ": - " & t
s = d.SerialNumber
MsgBox s
End Sub
Paste this into the click event of a Button on the same Form:
all the options worked great! Thank you to all of you.
One more question. Let's say: I get the serial number
for the hard disk where I installed my msaccess application
and I want it to work only in that Hard Disk. The hard disk serial I retrieve is 940839428 and I want to ensure it will
only work if the serial number I input (Somewhere) matches
with the hard disks'. Is this possible? I hope you understand what I want to do. Thank you in advanced.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.