Actually, getting the real Drive serial number is simple:
http://vbnet.mvps.org/index.html?code/disk/smartide.htm
Here is another way based on a posting by Larry Serflaten over in the
compiled
VB newsgroups...
Insert a Module and copy/paste this code into it...
Public Type HardDriveInfo
DriveLetter As String
VolumeName As String
SerialNumber As String
FormatType As String
TotalSize As String
FreeSize As String
End Type
Public Sub GetDriveInfo(DriveLetter As String, HardDrive As HardDriveInfo)
Dim WMI, SYS, DRV
Set WMI = GetObject("winmgmts:\\.\root\CIMV2")
Set SYS = WMI.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", 48)
For Each DRV In SYS
If StrComp(DRV.Name, Replace(DriveLetter, ":", "") & ":", vbTextCompare)
= 0 Then
With HardDrive
.DriveLetter = DRV.Name
.VolumeName = DRV.VolumeName
.SerialNumber = DRV.VolumeSerialNumber
.FormatType = DRV.FileSystem
.TotalSize = Format(DRV.Size / (10 ^ 6), "#,##0 MB")
.FreeSize = Format(DRV.FreeSpace / (10 ^ 6), "#,##0 MB")
End With
Exit For
End If
Next
End Sub
Now, in your own code, you can declare a variable of type HardDriveInfo,
call the GetDriveInfo subroutine (passing in the drive letter you are
interested in) and retrieve various information about that drive. Here is an
example...
Sub Test()
Dim HD As HardDriveInfo
GetDriveInfo "c", HD
Debug.Print "Drive Letter: " & HD.DriveLetter
Debug.Print "Volume Name: " & HD.VolumeName
Debug.Print "Serial Number: " & HD.SerialNumber
Debug.Print "Drive Format: " & HD.FormatType
Debug.Print "Total Size: " & HD.TotalSize
Debug.Print "Free Size: " & HD.FreeSize
End Sub
Rick