Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with GetVolumeInformation in Visual Basic 6

Not open for further replies.

Mr. Kiran V. Sutar

Newbie level 4
Dec 17, 2003
Reaction score
Trophy points
Mumbai, India
Activity points
getvolumeinformation windows xp

Hi Forum Members,
I have written a following small routine in VisualBasic6:

Dim strVolumeNameBuffer As String * 11 'Can only be 11 bytes
Dim strFileSystemNameBuffer, strClient As String

Private Declare Function GetVolumeInformation Lib "kernel32" 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

Private Sub btnExit_Click()
Unload Me
End Sub

Private Sub btnGetVolumeInfo_Click()
Dim itemp1 As Integer
Dim str1 As String

strDrive = Me.txtVolume.Text
strVolumeNameBuffer = Space(11)
strFileSystemNameBuffer = Space(255)
GetVolumeInformation Left(strDrive, 2) & "\", strVolumeNameBuffer, Len(strVolumeNameBuffer), lngVolumeSerialNumber, lngMaximumComponentLength, lngFileSystemFlags, strFileSystemNameBuffer, Len(strFileSystemNameBuffer)

str1 = "Drive : " & strDrive & vbCrLf
str1 = str1 & "VolumeNameBuffer : " & strVolumeNameBuffer & vbCrLf
str1 = str1 & "VolumeSerialNumber : " & Str(lngVolumeSerialNumber) & vbCrLf

str1 = str1 & "VolumeMaximumComponentLength : " & Str(lngMaximumComponentLength) & vbCrLf
str1 = str1 & "VolumeFileSystemFlags : " & Str(lngFileSystemFlags) & vbCrLf
str1 = str1 & "VolumeFileSystemNameBuffer : " & strFileSystemNameBuffer & vbCrLf
str1 = str1 & "VolumeFileSystemNameBufferSize : " & Str(Len(strFileSystemNameBuffer)) & vbCrLf
MsgBox str1

itemp1 = FreeFile()
Open Trim(App.Path & "\VolumeInfo.Txt") For Append Access Write As itemp1
Print #itemp1, str1
Close #itemp1

End Sub

To read the Volume Serial Number of the HDD (C:\).

The above code works well on Windows98, and shows the Volume Serial Number correctly.
If I execute the same code on Windows XP, sometimes it works and sometimes it doesn't. Following are the tested conditions where it works and where it does not work:

Test 1: WindowsXP (Laptop) having OfficeXP, NTFS File System, Logged as Administrator. It works OK. :)

Test 2: Windows XP (StandAlone Desktop PC), having OfficeXP, FAT32 File System, Logged as User having Administrative rights. It works OK. :)

Test 3: Windows XP (PC connected to NT Network), having WindowsXP on C Drive, NTFS File System, Logged as user having administrative rights. it does NOT work. the volume serial number is returned as 0. :(

Please inform me if I am doing any mistake in the coding or testing. :?: My basic intention is to read the Serial Number of the C Drive in all of the Windows Operating Systems. :cry:

Thanking you in advance.

With best regards from,
Mr. Kiran V. Sutar.

Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com