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))
I get errors like
107 Type 'Management.ManagementObjectCollection' is not defined. C:\Users\User\Documents\app\Form1.vb 4852 23 app
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.
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
Last edited by sapator; Mar 6th, 2010 at 09:57 PM.
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
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.
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.
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.