Results 1 to 4 of 4

Thread: Hard Drive Serial number

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    49

    Hard Drive Serial number

    Does anyone know how can I get the Hard Drive Serial number from a computer?

    PLease send me some code examples.
    Thanks,
    H.

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    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.  
    24.  
    25. To use it do this
    26. GotNum = VolumeSerialNumber("C:\")

    I think thats all you need.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3
    Hello: I just thought you may want to know this also.

    If I am not mistaken, this will not return a NETWORK drive serial number (Only the local drive).
    David M. Camp

  4. #4
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213
    I think Arc's code is much better, but here is a different way...

    Public Function SerialNumber() As Long
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim Drive As Object
    Set Drive = fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName(App.Path)))
    SerialNumber = Abs(Drive.SerialNumber)
    Set fso = Nothing
    Set Drive = Nothing
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width