Hello, How can i get the hard drive Serial Number.
The Physical one only :)
I spent 1 hour on google the only examples i found all had errors :(
Printable View
Hello, How can i get the hard drive Serial Number.
The Physical one only :)
I spent 1 hour on google the only examples i found all had errors :(
Have a look here:
http://www.vbforums.com/showthread.php?t=605589
The post i give references for the hd serial and modify the first post code to your needs.
WMI is probably the easiest. You can use Microsoft's WMI creator.
Also, if you tried and example and it didn't work, don't you think you should post it and the errors you're referring to?
That's much better than waiting for someone to give you the code.
I get errors likeCode:Dim objMan As New Management.ManagementClass("Win32_PhysicalMedia")
Dim objCol As Management.ManagementObjectCollection = objMan.GetInstances
Dim objItem As Management.ManagementObject
For Each objItem In objCol
Dim pi As Management.PropertyDataCollection = objItem.Properties
Console.WriteLine("SerialNumber: " & CType(pi.Item("SerialNumber").Value, String))
Console.WriteLine("Tag: " & CType(pi.Item("Tag").Value, String))
Thank you in advance :)Quote:
107 Type 'Management.ManagementObjectCollection' is not defined. C:\Users\User\Documents\app\Form1.vb 4852 23 app
Yes you must import system.management
add reference and import
Follow my directions in post 6 of this thread.
The errors are gone but the serial number looks like this.
I just have a bad feeling that this is not a serial number.
Um... I've read about this before.
If I'm not mistaken, it is correct. Your serial number is just in a hexadecimal format. You'll need to convert it to a string. Google that and I'm sure you'l come up with what you need.
Thank you for the reply weirddemon
This might be a stupid question.
How unique is this Serial Number do you know?
Hi.
Just to make sure it's the correct serial here is an API function so you can compare them...
Code:Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
<DllImport("kernel32.dll")> _
Private Shared Function GetVolumeInformation(ByVal PathName As String, ByVal VolumeNameBuffer As StringBuilder, ByVal VolumeNameSize As Int32, ByRef VolumeSerialNumber As Int32, ByRef MaximumComponentLength As Int32, ByRef FileSystemFlags As Int32, ByVal FileSystemNameBuffer As StringBuilder, ByVal FileSystemNameSize As Int32) As Long
End Function
Friend Function GetVolumeSerial(ByVal strDriveLetter As String) As String
Dim serNum As System.Int32 = 0
Dim maxCompLen As System.Int32 = 0
Dim VolLabel As StringBuilder = New StringBuilder(256)
Dim VolFlags As Int32 = New Int32
Dim FSName As StringBuilder = New StringBuilder(256)
strDriveLetter += ":\"
Dim Ret As Long = GetVolumeInformation(strDriveLetter, VolLabel, CType(VolLabel.Capacity, Int32), serNum, maxCompLen, VolFlags, FSName, CType(FSName.Capacity, Int32))
Return Convert.ToString(serNum)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'disk volume
GetVolumeSerial("c")
End Sub
End Class
Sorry i live in the stone age here (xp).
So if you have vista and above here is how you get the exact serial without modifications.
Code:Private Function ff()
Dim MOS As ManagementObjectSearcher
Dim MOC As Management.ManagementObjectCollection
Dim MO As Management.ManagementObject
MOS = New ManagementObjectSearcher("Select * From Win32_DiskDrive")
MOC = MOS.Get
Dim s As String
For Each MO In MOC
s = MO("Model")
s = MO("Name")
s = MO("SerialNumber")
Next
End Function
What you posted is just going to assign "SerialNumber' to s in each iteration...
Did you intend on concatenating the Model, Name and Serial?Code:For Each MO In MOC
s = MO("Model")
s = MO("Name")
s = MO("SerialNumber")
Next
How unique is this Serial Number do you know?
Code:Dim objMan As New Management.ManagementClass("Win32_PhysicalMedia")
Dim objCol As Management.ManagementObjectCollection = objMan.GetInstances
Dim objItem As Management.ManagementObject
For Each objItem In objCol
Dim pi As Management.PropertyDataCollection = objItem.Properties
Console.WriteLine("SerialNumber: " & CType(pi.Item("SerialNumber").Value, String))
Console.WriteLine("Tag: " & CType(pi.Item("Tag").Value, String))
Bruce Fox that was just an example so Pc_Not_Mac can see if that's the values he wants.
Also i think serial no is 1 in every model since many software houses use HD serial to lock programs.
If you want more security use it with something else.
P.E. HD and MAC address.Combine the values or each in it's own check.
Thank for the help sapator :)
I just wanted to know how unique is this Serial Number
and thank you for the answer :)
No problem :wave:
You can use HardDriveInfo.DLL to read the real serial number of hard disk easily. HardDriveInfo.DLL does not depend on the "support" libraries to get or fetch the details. Each Hard Disks have Unique Serial Number, some time it is necessary to get the hard disk serial number. So HardDriveInfo.DLL helps us to get the Hard disk serial number easily and efficiently, you can use this serial number to create an machine id or encrypt number.
Hard Drive
First of all, i'm against of "feeding" the programmer with stuff that he/she can create easily by himself.
Second please provide the page of this dll and a usable example because i think you're just spamming.