Results 1 to 7 of 7

Thread: Drive SerialNumber in Vista

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    2

    Drive SerialNumber in Vista

    Hello,
    I have vb6 app that uses FileSystemObject to extract the drive SerialNumber of "C:" as follows:
    Code:
    Public fs As New FileSystemObject
    For Each Drive In fs.Drives
        If Drive <> "A:" And Drive <> "B:" Then
            sDriveID = Drive.SerialNumber
            Exit For
        End If
    Next Drive
    The code work fine for Windows XP. However, it does not work for Vista! Any solutions?

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Drive SerialNumber in Vista

    Works fine on Vista here. No idea what your problem is except that your code as shown has problems.
    Code:
    Private Function StumblePastFloppiesReturnFirstDriveSerial() As Long
        Dim Drive As Scripting.Drive
        
        With New Scripting.FileSystemObject
            For Each Drive In .Drives
                If Drive <> "A:" And Drive <> "B:" Then
                    StumblePastFloppiesReturnFirstDriveSerial = Drive.SerialNumber
                    Exit For
                End If
            Next
        End With
    End Function

  3. #3
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Drive SerialNumber in Vista

    Welcome to VBForums.

    @dilettante - your code shows -1202017601 on my Vista. I don't know why it shows a negative value plus drive serial numbers generally have letters in them don't they?
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Drive SerialNumber in Vista

    It is a Long value. If you want letters display the Hex$() of the value.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    2

    Re: Drive SerialNumber in Vista

    dilettante,
    This is a WORKING peice of code! It works for anything UPTO WinXP. For Vista it just returns blank. That's what I have been told coz I hdo not have Vista installed.
    Besides, the code is in VB6. You seem to have modified it a bit for other versions. If you do have VB6 and Vista, do let me know if the original VB6 code works for Vista or not. Thanks.

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Drive SerialNumber in Vista

    The original code can't work.

    If it occurs inside a procedure, the Public declaration isn't legal. If it occurs outside a procedure the For loop isn't legal. And Drive was never declared at all.

    If I jack it around to make it legal it works fine in XP, Vista, Win7, etc.

    That's all the code I posted does: make it work at all on anything.

  7. #7
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Drive SerialNumber in Vista

    Quote Originally Posted by dilettante View Post
    Works fine on Vista here. No idea what your problem is except that your code as shown has problems.
    Code:
    Private Function StumblePastFloppiesReturnFirstDriveSerial() As Long
        Dim Drive As Scripting.Drive
        
        With New Scripting.FileSystemObject
            For Each Drive In .Drives
                If Drive <> "A:" And Drive <> "B:" Then
                    StumblePastFloppiesReturnFirstDriveSerial = Drive.SerialNumber
                    Exit For
                End If
            Next
        End With
    End Function
    Quote Originally Posted by hr_c View Post
    If you do have VB6 and Vista, do let me know if the original VB6 code works for Vista or not. Thanks.
    That code work on my Vista and WinXP.

    Ok I've changed it to Hex$?
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width