Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

  • 2 weeks later...
Posted

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

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...