Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hard disk serial reading

Status
Not open for further replies.

rogerarce

Technical User
Jan 24, 2002
57
CR
I was wondering if there's a chance that I can read
the hard disk' serial number with ms access? I would like
to use it as security.

Thank you for your help!

Roger
 
Below is some code I found at
Option Compare Database
Option Explicit

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"
 
Access 2k+
Paste this into a Form's Module:

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:

ShowDriveInfo ("c:")
 
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.

Roger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top