|  |  |  Free VB Projects 
				
					|  | Get disk serial number using the file system object (Windows 95/98/ME/NT/2000/2003/XP) |  Description:
			
			This VB code (function) enables you to retrieve the hard disk (partition) serial number. This serial number is generated by Windows (or DOS) when you format a disk partition.
 
 Keywords:
			
			Disk Serial Number, Hard Disk Serial, Drive Serial Number
 
 
 
      'Note: This code requires a referecne to the Microsoft Scripting Runtime library (SCRRUN.DLL)Return to VB projectsPrivate Sub Form_Load()
      
          'Show drive serial number for the current drive
          MsgBox " Drive serial number for " & Left(App.Path, 1) & ": " & GetDriveSerialNumber
          End
      
      End Sub
 Public Function GetDriveSerialNumber(Optional ByVal DriveLetter As String) As Long
      
          Dim fso As Object, Drv As Object
          
          'Create a FileSystemObject object
          Set fso = CreateObject("Scripting.FileSystemObject")
          
          'Assign the current drive letter if not specified
          If DriveLetter <> "" Then
              Set Drv = fso.GetDrive(DriveLetter)
          Else
              Set Drv = fso.GetDrive(fso.GetDriveName(App.Path))
          End If
      
          With Drv
              If .IsReady Then
                  DriveSerial = Abs(.SerialNumber)
              Else    '"Drive Not Ready!"
                  DriveSerial = -1
              End If
          End With
          
          'Clean up
          Set Drv = Nothing
          Set fso = Nothing
          
          GetDriveSerialNumber = DriveSerial
          
      End Function
 |