ZeroEffect Posted November 13, 2007 Posted November 13, 2007 (edited) I have found a couple of ways to get a serial number for a hard drive. One way is like this Dim fso As Scripting.FileSystemObject fso = New Scripting.FileSystemObject() TextBox1.Text = Hex(fso.GetDrive("C").SerialNumber()) That works great but the serial number would change if the drive is reformated. The other way is like this TextBox1.AppendText(vbCrLf) Dim hdCollection As New ArrayList() Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") Dim wmi_HD As New ManagementObject() For Each wmi_HD In searcher.Get Dim hd As New HardDrive() hd.Model = wmi_HD("Model").ToString() hd.Type = wmi_HD("InterfaceType").ToString() hdCollection.Add(hd) Next Dim searcher1 As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia") Dim i As Integer = 0 For Each wmi_HD In searcher1.Get() '// get the hard drive from collection '// using index Dim hd As HardDrive hd = hdCollection(i) '// get the hardware serial no. If wmi_HD("SerialNumber") = "" Then hd.serialNo = "None" Else hd.serialNo = wmi_HD("SerialNumber").ToString() i += 1 End If Next Dim hd1 As HardDrive Dim ii As Integer = 0 For Each hd1 In hdCollection ii += 1 TextBox1.Text = TextBox1.Text + "Disco Name: " + hd1.name + Chr(13) + Chr(10) TextBox1.Text = TextBox1.Text + "Disco #: " + ii.ToString + Chr(13) + Chr(10) TextBox1.Text = TextBox1.Text + "Model: " + hd1.Model + Chr(13) + Chr(10) TextBox1.Text = TextBox1.Text + "Tipo: " + hd1.Type + Chr(13) + Chr(10) TextBox1.Text = TextBox1.Text + "Serial No: " + hd1.serialNo + Chr(13) + Chr(10) + Chr(13) + Chr(10) Next This works great because it returns the physical HD serial number but I can't tell which drive is the "C" drive if there is more than one drive. I want to use the Physical HD serial number and hash it to make an activation password for my application. Is there a way to do this? Thanks ZeroEffect Edited November 13, 2007 by ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Administrators PlausiblyDamp Posted November 14, 2007 Administrators Posted November 14, 2007 WMI should expose a DriveID property - this should be the drive letter. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ZeroEffect Posted November 27, 2007 Author Posted November 27, 2007 Thanks for the reply PlausiblyDamp. I went through the MSDN web site and found nothing for the DriveID in the WMI. Do you have an example or another place to look? Thanks ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.