Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strange results with GetVolumeInformation

Posted on 1999-09-23
5
Medium Priority
?
241 Views
Last Modified: 2010-05-02
When I use GetVolumeInformation with the following functions with certian drives serial numbers I get results like this:

454D-7E11 will return 454D-700000000000
1141-6D18 will return 1141-6000000000000000000

Are these serial numbers invalid or is there a bug in the code?


Heres the code I don't remember where I got it from:



                ' Add to a module
                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



                'Add the following code to the form

                Public Function SerialNumber(ByVal Pathname As String) As String

                    Dim r As Long
                   
                    Dim DrvVolumeName As String
                    Dim DrvSerialNo As String
                     
                   
                     
                    rgbGetVolumeInformationRDI Pathname$, DrvVolumeName$, DrvSerialNo$
                     SerialNumber = DrvSerialNo$
                     
                    '     'show the results
                End Function


                Private Sub rgbGetVolumeInformationRDI(Pathname$, DrvVolumeName$, DrvSerialNo$)

                     
                    '     'create working variables
                    '     'to keep it simple, use dummy variables for info
                    '     'we're not interested in right now
                    Dim r As Long
                    Dim pos As Integer
                    Dim HiWord As Long
                    Dim HiHexStr As String
                    Dim LoWord As Long
                    Dim LoHexStr As String
                    Dim VolumeSN As Long
                    Dim MaxFNLen As Long
                    Dim UnusedStr As String
                    Dim UnusedVal1 As Long
                    Dim UnusedVal2 As Long
                    '     'pad the strings
                    DrvVolumeName$ = Space$(14)
                    UnusedStr$ = Space$(32)
                    '     'do what it says
                    r& = GetVolumeInformation(Pathname$, _
                    DrvVolumeName$, Len(DrvVolumeName$), VolumeSN&, _
                    UnusedVal1&, UnusedVal2&, UnusedStr$, Len(UnusedStr$))
                    '     'error check
                    If r& = 0 Then Exit Sub
                    '     'determine the volume label
                    pos% = InStr(DrvVolumeName$, Chr$(0))
                    If pos% Then DrvVolumeName$ = Left$(DrvVolumeName$, pos% - 1)
                    If Len(Trim$(DrvVolumeName$)) = 0 Then DrvVolumeName$ = "(no label)"
                     
                    '     'determine the drive volume id
                    HiWord& = GetHiWord(VolumeSN&) And &HFFFF&
                    LoWord& = GetLoWord(VolumeSN&) And &HFFFF&
                     
                    HiHexStr$ = Format$(Hex(HiWord&), "0000")
                    LoHexStr$ = Format$(Hex(LoWord&), "0000")
                     
                    DrvSerialNo$ = HiHexStr$ & "-" & LoHexStr$
                End Sub



                Private Function GetHiWord(dw As Long) As Integer

                     

                    If dw& And &H80000000 Then
                        GetHiWord% = (dw& \ 65535) - 1
                    Else: GetHiWord% = dw& \ 65535
                    End If

                End Function



                Private Function GetLoWord(dw As Long) As Integer

                     

                    If dw& And &H8000& Then
                        GetLoWord% = &H8000 Or (dw& And &H7FFF&)
                    Else: GetLoWord% = dw& And &HFFFF&
                    End If

                End Function






0
Comment
Question by:Neal Hartman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:P1
ID: 2070815
'One of many ways, to do it.  Look Ma, no math!

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal bytes As Long)

' Return the low word of a Long value
Function GetLoWord(ByVal value As Long) As Integer
CopyMemory GetLoWord, value, 2
End Function

' Return the high word of a Long value.
Function GetHiWord(ByVal value As Long) As Integer
CopyMemory GetHiWord, ByVal VarPtr(value) + 2, 2
End Function
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2070869
No, just do this:

Instead of
HiHexStr$ = Format$(Hex(HiWord&), "0000")
LoHexStr$ = Format$(Hex(LoWord&), "0000")

Use
HiHexStr$ = Right("0000" & Hex(HiWord&), 4)
LoHexStr$ = Right("0000" & Hex(LoWord&), 4)
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 2070941
I tried both solutions and only Erick37's worked. Answer the Q Erick and I'll send you the points. Thanks to both of you for a quick response.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 400 total points
ID: 2070948
Comment as answer, thanks!
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6862624
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

In efforts to help all Members maintain their open questions, this is a reminder to click your Member Profile, expand your question history and find/update all your Open and Locked questions.
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question