Get And Display Hard Disk Serial Number In VB.NET
Submitted by donbermoy on Thursday, August 6, 2015 - 13:10.
This tutorial is all about getting and displaying the hard disk serial number for a complete disk but not in just a single drive using vb.net.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add only one textbox named TextBox1 in your Form.
3. Now, lets do the coding.
First, we will import the following libraries below to access the hard disk information.
Then, we will declare a variable for getting the Thread attribute.
Also declare variables for ArrayList, ManagementObjectSearcher, and ManagementObject inside the Form_Load.
Then, we will get the model and the type of the hard drive by using the for each loop with our searcher variable created above.
Then display all the serial numbers on the textbox by the hdCollection.
- Imports System.Collections
- Imports System.Management
- Dim WindowsApplication1 As System.STAThreadAttribute()
- 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 Class1.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 Class1.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
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISwareAdd new comment
- 3287 views