dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jan 15, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


GetDriveInfo - Drive serial number and other data

Private Declare Function GetVolumeInformation& Lib "kernel32" Alias _
    "GetVolumeInformationA" (ByVal lpRootPathName As String, _
    ByVal pVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
    lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
    lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _
    ByVal nFileSystemNameSize As Long)

Const MAX_PATH = 260

Const FILE_CASE_SENSITIVE_SEARCH = &H1
Const FILE_CASE_PRESERVED_NAMES = &H2
Const FILE_UNICODE_ON_DISK = &H4
Const FILE_PERSISTENT_ACLS = &H8
Const FILE_FILE_COMPRESSION = &H10
Const FILE_VOLUME_IS_COMPRESSED = &H8000

' return volume name, serial number and file system (eg "FAT") for a given drive
' it fails with removable drives if the disk isn't in place
' the FileSystemFlags argument is a combination of the FILE_* constats
' (see MSDN for additional information)
'
' you can specify an UNC for the drive name 
' (e.g."\\MyServer\MyShare as \\MyServer\MyShare\"
' Under Windows95/98 the serial number of network drives isn't returned
'
' Returns True if all information has been retrieved successfully

Function GetDriveInfo(ByVal DriveName As String, Optional VolumeName As String, _
    Optional SerialNumber As Long, Optional FileSystem As String, _
    Optional FileSystemFlags As Long) As Boolean
    
    Dim ignore As Long
    
    ' if it isn't a UNC path, enforce the correct format
    If InStr(DriveName, "\\") = 0 Then
        DriveName = Left$(DriveName, 1) & ":\"
    End If
    
    ' prepare receiving buffers
    SerialNumber = 0
    FileSystemFlags = 0
    VolumeName = String$(MAX_PATH, 0)
    FileSystem = String$(MAX_PATH, 0)
    
    ' The API function return a non-zero value if successful
    GetDriveInfo = GetVolumeInformation(DriveName, VolumeName, Len(VolumeName), _
        SerialNumber, ignore, FileSystemFlags, FileSystem, Len(FileSystem))
    ' drop characters in excess
    VolumeName = Left$(VolumeName, InStr(VolumeName, vbNullChar) - 1)
    FileSystem = Left$(FileSystem, InStr(FileSystem, vbNullChar) - 1)
    
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date