0

There are some ways to get the serial number of a hard drive. I've searched and designed code like this:

Public Function GetDriveSerialNumber() As String
    Dim DriveSerial As Long
    Dim fso As Object, Drv As Object

    fso = CreateObject("Scripting.FileSystemObject")
    Drv = fso.GetDrive(fso.GetDriveName("C:\"))

    With Drv
        If .IsReady Then
            DriveSerial = .SerialNumber
        Else 
            DriveSerial = -1
        End If
    End With
    Drv = Nothing
    fso = Nothing
    GetDriveSerialNumber = Hex(DriveSerial)
End Function

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    MsgBox(GetDriveSerialNumber(), vbOKOnly, "Serial")
End Sub

Within the Stack Overflow site, there are many code blocks like that. When I run the code it gives me my hard drive C's serial number like "349B3214".

I haven't tried to format my computer, but does it change after formatting? I mean when I run, it says your serial is "349B3214". If I format my computer and run this code again, does it gives me the same serial or different?

Bugs
  • 4,491
  • 9
  • 32
  • 41
Rose_The_Only
  • 238
  • 9
  • 21
  • 1
    No, this is the [Volume Serial Number](https://msdn.microsoft.com/en-us/library/49fsbc5e(v=vs.84).aspx) and [formatting the volume changes that number](https://en.wikipedia.org/wiki/Volume_serial_number) – Steve Mar 18 '17 at 20:44
  • Thanks Steve. Im looking for a way to get a "number" that never changes after formatting. As i see this is not that one :) Thank you again. – Rose_The_Only Mar 18 '17 at 20:51
  • [This question](http://stackoverflow.com/questions/4084402/get-hard-disk-serial-number) (albeit in C#) could give you some searching ideas. – Steve Mar 18 '17 at 20:58
  • Steve, i also tried to get Mainboard Serial no and CPU serial no. The codes are below. They are working. Can we say that these functions give us the permanent "numbers" that never changes after formatting.? – Rose_The_Only Mar 18 '17 at 21:04
  • CPU and Mainboard are not formatted..... – Steve Mar 18 '17 at 21:09
  • Are you looking for an UniqueIdentifier of a PC?, You can find other ideas here http://stackoverflow.com/questions/9546228/how-to-detect-the-original-mac-address-after-it-has-been-spoofed/9546552#9546552 – Steve Mar 18 '17 at 21:11
  • Yes, really looking for something UniqueIdentifier of a PC. Examining your link. Thanks – Rose_The_Only Mar 18 '17 at 21:17
  • In all likelihood, depending on what you are doing, you probably want a hash of assorted identifiers possibly including something to identify the software as well – Ňɏssa Pøngjǣrdenlarp Mar 18 '17 at 21:18

0 Answers0