|
-
May 13th, 2011, 10:57 PM
#1
Thread Starter
New Member
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?
-
May 14th, 2011, 12:32 PM
#2
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
-
May 14th, 2011, 05:09 PM
#3
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.
-
May 14th, 2011, 08:33 PM
#4
Re: Drive SerialNumber in Vista
It is a Long value. If you want letters display the Hex$() of the value.
-
May 14th, 2011, 09:35 PM
#5
Thread Starter
New Member
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.
-
May 15th, 2011, 06:54 AM
#6
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.
-
May 15th, 2011, 10:45 AM
#7
Re: Drive SerialNumber in Vista
 Originally Posted by dilettante
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
 Originally Posted by hr_c
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|