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 SkipVought 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 number detection 1

Status
Not open for further replies.

ByzantianX

Programmer
Dec 18, 2000
103
0
0
I was wondering if there's an API function or some other way to get HD serial number. Please, help me!
Thanks in advance!
 
This is Remedy's answered

remedy (Programmer) Jul 27, 2001
It's easy using FileSystemObject:

Private Function GetSerialNum(ByVal DriveName As String) As Long

Dim loFSO As FileSystemObject
Dim loDrive As Drive

Set loFSO = New FileSystemObject
Set loDrive = loFSO.GetDrive(DriveName)

If loDrive.IsReady Then
GetSerialNum = loDrive.SerialNumber
Else
GetSerialNum = 0
End If

Set loFSO = Nothing
End Function

Private Declare Function GetVolumeInformation Lib "kernel32.dll" 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

Or otherwise you can us API:
(in that case you can get even more information as you can see)

Private Function GetSerialNum(DriveName As String) As Long

Dim lsVolumeName As String
Dim liSerialNum As Long
Dim lsSerNumStr As String
Dim liMaxCompLength As Long
Dim liFileSysFlags As Long
Dim lsFileSysName As String
Dim liRetval As Long

lsVolumeName = Space$(256)
lsFileSysName = Space$(256)

liRetval = GetVolumeInformation(DriveName, lsVolumeName, 256, liSerialNum, liMaxCompLength, liFileSysFlags, lsFileSysName, 256)

GetSerialNum = liSerialNum
End Function

Remedy
 
Thank you very much! That works fine but my trouble is that I'm using Access 2.0 and whenever I try to call GetVolumeInformation I'm getting the error message:"Error loading dll". I guess that's because Access 2.0 is 16-bit application. Is there any API function analogue to the GetVolumeInformation that could be used in 16-bit applications?
 
I use Access97. The first function (without API) that I tested works just fine. I really don't know if it'll work with 16-bit application.

This function needs "Microsoft Scripting Runtime" reference (vba332.dll, usually in folder C:\Program Files\Common Files\Microsoft Shared\VBA).

To set a reference to your Access(97) database:
1.Open the Module window.
2.On the Tools menu, click References, and click Browse in the References dialog box.
3.Seek then check the "Microsoft Scripting Runtime"
4.Click OK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top