VB Code:
  1. Public Declare Function GetVolumeSerialNumber 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
  2. Public Function VolumeSerialNumber(ByVal RootPath As String) As String
  3.     Dim VolLabel As String
  4.     Dim VolSize As Long
  5.     Dim Serial As Long
  6.     Dim MaxLen As Long
  7.     Dim Flags As Long
  8.     Dim Name As String
  9.     Dim NameSize As Long
  10.     Dim s As String
  11.  
  12.     If GetVolumeSerialNumber(RootPath, VolLabel, VolSize, Serial, MaxLen, Flags, Name, NameSize) Then
  13.         'Create an 8 character string
  14.         s = Format(Hex(Serial), "00000000")
  15.         'Adds the '-' between the first 4 characters and the last 4 characters
  16.         VolumeSerialNumber = Left(s, 4) + "-" + Right(s, 4)
  17.     Else
  18.         'If the call to API function fails the function returns a zero serial number
  19.         VolumeSerialNumber = "0000-0000"
  20.     End If
  21. End Function
  22.  
  23. ' Usage :
  24.  
  25. GotNum = VolumeSerialNumber("C:\")
  26.  
  27.  
  28. ' OR ##########################
  29.  
  30. Public Function SerialNumber() As Long
  31.  
  32. Dim fso As Object
  33.  
  34. Set fso = CreateObject("Scripting.FileSystemObject")
  35.  
  36. Dim Drive As Object
  37.  
  38. Set Drive = fso.GetDrive(fso.GetDriveName
  39. (fso.GetAbsolutePathName(App.Path)))
  40.  
  41. SerialNumber = Abs(Drive.SerialNumber)
  42.  
  43. Set fso = Nothing
  44.  
  45. Set Drive = Nothing
  46.  
  47. End Function