How can I get the serial number of a Hard Drive ?
Printable View
How can I get the serial number of a Hard Drive ?
No .NET way for it. Look here , it has build a class library for it using GetVolumeInfroamtion API
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 !
Found this code, maby usefull? Will display your HD Serial
VB Code:
Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator bienu.MoveNext() MsgBox(bienu.Current.Properties("SerialNumber").Value.ToString) End Sub End Class
what is 'bi' in the code?
VB Code:
Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
Hmmm, lets see :D
VB Code:
Dim biClass As New ManagementClass("Win32_BIOS") Dim bi As ManagementObjectCollection = biClass.GetInstances() Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator Msgbox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
This code is throwing error . What's wrong !:rolleyes:Quote:
Originally posted by phrozeman
Hmmm, lets see :D
VB Code:
Dim biClass As New ManagementClass("Win32_BIOS") Dim bi As ManagementObjectCollection = biClass.GetInstances() Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator Msgbox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
I don't have an error but it does not show the SerialNumber.Quote:
Originally posted by Pirate
This code is throwing error . What's wrong !:rolleyes:
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
For me it throws this error
"index was outside the bounds of the array."
I did added a reference to "System.Management" .There error says :
Index was outside the bounds of array "
I can't see any declaration for any array . Maybe the func needs one or ....I dunno really .:confused:
I also had the same message. I added bienu.MoveNext() and message disappeared. I think that this is an array that you get after ennumerationQuote:
Originally posted by Pirate
I can't see any declaration for any array . Maybe the func needs one or ....I dunno really .:confused:
I think this code has nothing to do with HD serial .:D
anyways , this api call will do it
VB Code:
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 Function GetSerialNumber(ByRef strDrive As String) As Integer Dim SerialNum As Integer Dim Res As Integer Dim Temp1 As String Dim Temp2 As String ' Temp1 = New String(Chr(0), 255) Temp2 = New String(Chr(0), 255) Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2)) GetSerialNumber = SerialNum End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox("" & GetSerialNumber("C:\"), MsgBoxStyle.OKOnly, "HD Serial Number") End Sub
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????:rolleyes:
My code returns negative value , (-16579862.....).Is this possible !:rolleyes:
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
Oke Guys, forgot the movenext line, to go to the first HD
It will work, but don't ask how :P
VB Code:
Imports System.Management Dim biClass As New ManagementClass("Win32_BIOS") Dim bi As ManagementObjectCollection = biClass.GetInstances() Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator bienu.MoveNext() MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
It still shows the empty string instead of Number
Works fine here
pirate, what about you.
Can it be that my HD does not have serial #?
With MoveNext it returns "0000000' here, not sure about the number of 0s :)
Pirate, didnt that class library work fine?
It returns value but can this be a serial number(1234567890)????Quote:
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:
Imports System.Management Dim biClass As New ManagementClass("Win32_BIOS") Dim bi As ManagementObjectCollection = biClass.GetInstances() Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator bienu.MoveNext() MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
Try my api call , to verify you have serial ?Quote:
Originally posted by Iouri
pirate, what about you.
Can it be that my HD does not have serial #?
Every HD has an serial
Long Live WMI:mad:
aaaaah forget it .I will go for API better than this mess.
thanx anyways guys .:cool:
Err do you know what you are talking about?Quote:
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:
Imports System.Management Dim biClass As New ManagementClass("Win32_BIOS") Dim bi As ManagementObjectCollection = biClass.GetInstances() Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator bienu.MoveNext() MsgBox("Serial No: " & bienu.Current.Properties("SerialNumber").Value.ToString)
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") :ehh:
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.
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
Have you read this post?Quote:
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") :ehh:
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.
You should use Win32_PhysicalMedia instead of Win32_BIOS.
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 :)
Some of the WMI methods are not available in all Windows. This is well documented by MS in MSDN library.
Just curious (and stoopid too I guess..)....
Why would one want to retrieve you hd serial number in an app???
This is for security purpose and the code supports only Win XP.. I suggest to use dongle hardware for securing the app.
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) .
:confused: