Results 1 to 35 of 35

Thread: HD serial number![Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    HD serial number![Resolved]

    How can I get the serial number of a Hard Drive ?
    Last edited by Pirate; Feb 17th, 2003 at 02:26 PM.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    No .NET way for it. Look here , it has build a class library for it using GetVolumeInfroamtion API

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's what I was afraid of !
    I know it can be done through API easily but ...
    that's alright , Thanx for the help Lunatic3 !

  4. #4
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    Found this code, maby usefull? Will display your HD Serial

    VB Code:
    1. Imports System.Management
    2. Public Class Form1
    3.     Inherits System.Windows.Forms.Form
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    7.         bienu.MoveNext()
    8.         MsgBox(bienu.Current.Properties("SerialNumber").Value.ToString)
    9.     End Sub
    10. End Class
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    what is 'bi' in the code?
    VB Code:
    1. Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator

  6. #6
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    Hmmm, lets see

    VB Code:
    1. Dim biClass As New ManagementClass("Win32_BIOS")
    2.         Dim bi As ManagementObjectCollection = biClass.GetInstances()
    3.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    4.  
    5. Msgbox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by phrozeman
    Hmmm, lets see

    VB Code:
    1. Dim biClass As New ManagementClass("Win32_BIOS")
    2.         Dim bi As ManagementObjectCollection = biClass.GetInstances()
    3.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    4.  
    5. Msgbox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
    This code is throwing error . What's wrong !

  8. #8
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    Originally posted by Pirate
    This code is throwing error . What's wrong !
    I don't have an error but it does not show the SerialNumber.


    If it throws an error - did you add the reference to the WMI

    It is under NET tab System.Management
    Also you have to import
    System.Management
    Iouri Boutchkine

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    For me it throws this error
    "index was outside the bounds of the array."

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I did added a reference to "System.Management" .There error says :
    Index was outside the bounds of array "

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I can't see any declaration for any array . Maybe the func needs one or ....I dunno really .

  12. #12
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    Originally posted by Pirate
    I can't see any declaration for any array . Maybe the func needs one or ....I dunno really .
    I also had the same message. I added bienu.MoveNext() and message disappeared. I think that this is an array that you get after ennumeration
    Iouri Boutchkine

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I think this code has nothing to do with HD serial .

  14. #14

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    anyways , this api call will do it
    VB Code:
    1. Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Short, ByRef lpVolumeSerialNumber As Integer, ByRef lpMaximumComponentLength As Integer, ByRef lpFileSystemFlags As Integer, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Integer) As Integer
    2.  
    3.     Function GetSerialNumber(ByRef strDrive As String) As Integer
    4.         Dim SerialNum As Integer
    5.         Dim Res As Integer
    6.         Dim Temp1 As String
    7.         Dim Temp2 As String
    8.         '
    9.         Temp1 = New String(Chr(0), 255)
    10.         Temp2 = New String(Chr(0), 255)
    11.         Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
    12.         GetSerialNumber = SerialNum
    13.  
    14.     End Function
    15.  
    16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    17.         MsgBox("" & GetSerialNumber("C:\"), MsgBoxStyle.OKOnly, "HD  Serial Number")
    18.     End Sub

  15. #15
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    Hard to say. THe whole WMI stuff is very strange. I have manged to write plenty of codes about different devices with WMI. But still cannot get it to the full extent. Check this site. Looks beautiful, but what the heck is that????
    Iouri Boutchkine

  16. #16

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    My code returns negative value , (-16579862.....).Is this possible !

  17. #17
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    I don't think that HD serial Nmber can be negative. My code does not return anything. I think that we might have different collection returnd by ennumeration. And when we use MoveNext I go to something without number and you are moving to something with negative number. Try to add another MoveNext and see if you will get something different
    Iouri Boutchkine

  18. #18
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    Oke Guys, forgot the movenext line, to go to the first HD
    It will work, but don't ask how :P
    VB Code:
    1. Imports System.Management
    2.  
    3. Dim biClass As New ManagementClass("Win32_BIOS")
    4.         Dim bi As ManagementObjectCollection = biClass.GetInstances()
    5.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    6.         bienu.MoveNext()
    7.         MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  19. #19
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    It still shows the empty string instead of Number
    Iouri Boutchkine

  20. #20
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    Works fine here
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  21. #21
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    pirate, what about you.
    Can it be that my HD does not have serial #?
    Iouri Boutchkine

  22. #22
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    With MoveNext it returns "0000000' here, not sure about the number of 0s

    Pirate, didnt that class library work fine?

  23. #23

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by phrozeman
    Oke Guys, forgot the movenext line, to go to the first HD
    It will work, but don't ask how :P
    VB Code:
    1. Imports System.Management
    2.  
    3. Dim biClass As New ManagementClass("Win32_BIOS")
    4.         Dim bi As ManagementObjectCollection = biClass.GetInstances()
    5.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    6.         bienu.MoveNext()
    7.         MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
    It returns value but can this be a serial number(1234567890)????

  24. #24

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Iouri
    pirate, what about you.
    Can it be that my HD does not have serial #?
    Try my api call , to verify you have serial ?

  25. #25
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    Every HD has an serial
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  26. #26
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    Long Live WMI
    Iouri Boutchkine

  27. #27

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    aaaaah forget it .I will go for API better than this mess.
    thanx anyways guys .

  28. #28
    New Member
    Join Date
    Aug 2004
    Posts
    1
    Originally posted by phrozeman
    Oke Guys, forgot the movenext line, to go to the first HD
    It will work, but don't ask how :P
    VB Code:
    1. Imports System.Management
    2.  
    3. Dim biClass As New ManagementClass("Win32_BIOS")
    4.         Dim bi As ManagementObjectCollection = biClass.GetInstances()
    5.         Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
    6.         bienu.MoveNext()
    7.         MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
    Err do you know what you are talking about?

    This brings your BIOS Serial #, NOT the HD serial number. (If your BIOS support it, of course.)

    No wonder why the parameter is ("Win32_BIOS")

    However, I only have the VB6 version to get the *REAL* HD serial number (once again, when it is supported too), not the Volume serial number.

  29. #29
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784
    That API code is only used for getting the O/S Serial No., you will get other O/S No. when the HDD formatted..

    Regards
    Winan

  30. #30
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by frosted
    Err do you know what you are talking about?

    This brings your BIOS Serial #, NOT the HD serial number. (If your BIOS support it, of course.)

    No wonder why the parameter is ("Win32_BIOS")

    However, I only have the VB6 version to get the *REAL* HD serial number (once again, when it is supported too), not the Volume serial number.
    Have you read this post?
    You should use Win32_PhysicalMedia instead of Win32_BIOS.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  31. #31
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Hi Lunatic3, I'm curious, so I read the post you link, but if I well understand your solution is good only for XP, or I misunderstood your words, or there were some news on this?
    Thanks in advance
    Live long and prosper (Mr. Spock)

  32. #32
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Some of the WMI methods are not available in all Windows. This is well documented by MS in MSDN library.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  33. #33
    Registered User NicoNel2000's Avatar
    Join Date
    Feb 2004
    Location
    Beijing - China
    Posts
    296
    Just curious (and stoopid too I guess..)....
    Why would one want to retrieve you hd serial number in an app???

  34. #34
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784
    This is for security purpose and the code supports only Win XP.. I suggest to use dongle hardware for securing the app.

  35. #35

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can we stop this discussion and let this old thread float down.Digging in old threads is very stupid esp when the thread is marked [Resolved] (regardless whether true or not) .


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