|
-
Feb 14th, 2003, 02:22 PM
#1
Thread Starter
Sleep mode
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.
-
Feb 14th, 2003, 04:24 PM
#2
Frenzied Member
No .NET way for it. Look here , it has build a class library for it using GetVolumeInfroamtion API
-
Feb 14th, 2003, 04:29 PM
#3
Thread Starter
Sleep mode
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 !
-
Feb 15th, 2003, 04:42 PM
#4
Hyperactive Member
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
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 15th, 2003, 05:03 PM
#5
Frenzied Member
what is 'bi' in the code?
VB Code:
Dim bienu As ManagementObjectCollection.ManagementObjectEnumerator = bi.GetEnumerator
-
Feb 16th, 2003, 10:35 AM
#6
Hyperactive Member
Hmmm, lets see 
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)
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 16th, 2003, 12:02 PM
#7
Thread Starter
Sleep mode
Originally posted by phrozeman
Hmmm, lets see 
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 !
-
Feb 16th, 2003, 12:08 PM
#8
Member
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
-
Feb 16th, 2003, 12:11 PM
#9
Frenzied Member
For me it throws this error
"index was outside the bounds of the array."
-
Feb 16th, 2003, 12:11 PM
#10
Thread Starter
Sleep mode
I did added a reference to "System.Management" .There error says :
Index was outside the bounds of array "
-
Feb 16th, 2003, 12:14 PM
#11
Thread Starter
Sleep mode
I can't see any declaration for any array . Maybe the func needs one or ....I dunno really .
-
Feb 16th, 2003, 12:21 PM
#12
Member
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
-
Feb 16th, 2003, 12:26 PM
#13
Thread Starter
Sleep mode
I think this code has nothing to do with HD serial .
-
Feb 16th, 2003, 12:34 PM
#14
Thread Starter
Sleep mode
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
-
Feb 16th, 2003, 12:34 PM
#15
Member
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????
-
Feb 16th, 2003, 12:38 PM
#16
Thread Starter
Sleep mode
My code returns negative value , (-16579862.....).Is this possible !
-
Feb 16th, 2003, 12:43 PM
#17
Member
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
-
Feb 16th, 2003, 02:23 PM
#18
Hyperactive Member
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)
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 16th, 2003, 02:35 PM
#19
Member
It still shows the empty string instead of Number
-
Feb 16th, 2003, 02:40 PM
#20
Hyperactive Member
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 16th, 2003, 02:43 PM
#21
Member
pirate, what about you.
Can it be that my HD does not have serial #?
-
Feb 16th, 2003, 02:55 PM
#22
Frenzied Member
With MoveNext it returns "0000000' here, not sure about the number of 0s 
Pirate, didnt that class library work fine?
-
Feb 16th, 2003, 10:04 PM
#23
Thread Starter
Sleep mode
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)
It returns value but can this be a serial number(1234567890)????
-
Feb 16th, 2003, 10:10 PM
#24
Thread Starter
Sleep mode
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 ?
-
Feb 17th, 2003, 03:26 AM
#25
Hyperactive Member
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 17th, 2003, 10:53 AM
#26
Member
Long Live WMI
-
Feb 17th, 2003, 02:24 PM
#27
Thread Starter
Sleep mode
aaaaah forget it .I will go for API better than this mess.
thanx anyways guys .
-
Aug 30th, 2004, 12:35 PM
#28
New Member
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)
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.
-
Aug 30th, 2004, 09:37 PM
#29
Fanatic Member
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
-
Aug 30th, 2004, 09:40 PM
#30
Frenzied Member
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
-
Aug 31st, 2004, 02:49 AM
#31
Hyperactive Member
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)
-
Aug 31st, 2004, 02:52 AM
#32
Frenzied Member
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
-
Aug 31st, 2004, 03:23 AM
#33
Registered User
Just curious (and stoopid too I guess..)....
Why would one want to retrieve you hd serial number in an app???
-
Aug 31st, 2004, 03:28 AM
#34
Fanatic Member
This is for security purpose and the code supports only Win XP.. I suggest to use dongle hardware for securing the app.
-
Aug 31st, 2004, 07:27 AM
#35
Thread Starter
Sleep mode
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|