GetVolumeInformation Function

Declare Function GetVolumeInformation 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

Platforms

Description & Usage

GetVolumeInformation retrieves information describing a disk volume and the file system it uses. This information includes things such as the volume label and the disk's serial number.

Return Value

If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

lpRootPathName
The root directory of the disk volume to be described. This directory must include a trailing backslash character. For example, to describe the C: drive, this would be "C:\".
lpVolumeNameBuffer
Receives the null-terminated volume label of the volume. This string must be large enough to receive the text.
nVolumeNameSize
The length of the string passed as lpVolumeNameBuffer.
lpVolumeSerialNumber
Receives the serial number of the volume. When displayed, this value should be shown in hexadecimal with a dash before the last four hex digits. Windows 95/98: If the volume is a netword drive, the serial number will not be retrieved.
lpMaximumComponentLength
Receives the maximum length of a file name component supported by the file system. A file name component is any portion of a file name between backslashes. This value is used primarily to determine if the volume supports long file names or if it is limited to the old 8.3 system.
lpFileSystemFlags
A combination of the following flags describing other features of the file system used by the volume:
FS_CASE_IS_PRESERVED
The file system preserves the case of file names.
FS_CASE_SENSITIVE
The file system uses case-sensitive file names.
FS_UNICODE_STORED_ON_DISK
The file system supports Unicode in file names as they appear on disk.
FS_PERSISTENT_ACLS
The file system preserves and enforces access control lists (ACLs).
FS_FILE_COMPRESSION
The file system supports file-based compression, where individual files can be compressed while others are not.
FS_VOL_IS_COMPRESSED
The entire volume is compressed; for example, DoubleSpace has been used on the disk.
FILE_NAMED_STREAMS
The file system supports named streams.
FILE_SUPPORTS_ENCRYPTION
The file system supports the Encrypted File System (EFS).
FILE_SUPPORTS_OBJECT_IDS
The file system supports object identifiers.
FILE_SUPPORTS_REPARSE_POINTS
The file system supports reparse points.
FILE_SUPPORTS_SPARSE_FILES
The file system supports sparse files.
FILE_VOLUME_QUOTAS
The file system supports disk quotas.
lpFileSystemNameBuffer
Receives the null-terminated name of the file system. This string must be long enough to receive the text.
nFileSystemNameSize
The length of the string passed as lpFileSystemNameBuffer.

Constant Definitions

Const FS_CASE_IS_PRESERVED = &H2
Const FS_CASE_SENSITIVE = &H1
Const FS_UNICODE_STORED_ON_DISK = &H4
Const FS_PERSISTENT_ACLS = &H8
Const FS_FILE_COMPRESSION = &H10
Const FS_VOLUME_IS_COMPRESSED = &H8000
Const FILE_NAMED_STREAMS = &H40000
Const FILE_SUPPORTS_ENCRYPTION = &H20000
Const FILE_SUPPORTS_OBJECT_IDS = &H10000
Const FILE_SUPPORTS_REPARSE_POINTS = &H80
Const FILE_SUPPORTS_SPARSE_FILES = &H40
Const FILE_VOLUME_QUOTAS = &H20 

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function GetVolumeInformation 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

' Display the volume label, serial number, and file system name
' of the C: drive.  Note how the serial number value is manipulated to
' display it properly.
Dim volname As String   ' receives volume name of C:
Dim sn As Long          ' receives serial number of C:
Dim snstr As String     ' display form of serial number
Dim maxcomplen As Long  ' receives maximum component length
Dim sysflags As Long    ' receives file system flags
Dim sysname As String   ' receives the file system name
Dim retval As Long      ' return value

' Initialize string buffers.
volname = Space(256)
sysname = Space(256)
' Get information about the C: drive's volume.
retval = GetVolumeInformation("C:\", volname, Len(volname), sn, maxcomplen, _
	sysflags, sysname, Len(sysname))
' Remove the trailing nulls from the two strings.
volname = Left(volname, InStr(volname, vbNullChar) - 1)
sysname = Left(sysname, InStr(sysname, vbNullChar) - 1)
' Format the serial number properly.
snstr = Trim(Hex(sn))
snstr = String(8 - Len(snstr), "0") & snstr
snstr = Left(snstr, 4) & "-" & Right(snstr, 4)
' Display the volume name, serial number, and file system name.
Debug.Print "Volume Name: "; volname
Debug.Print "Serial Number: "; snstr
Debug.Print "File System: "; sysname

See Also

SetVolumeLabel

Category

File System

Back to the Function list.
Back to the Reference section.


Last Modified: June 4, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getvolumeinformation.html