To get the Serial # of HDD using C#
Namespace :
Imports System.Management
Code:
Dim devid As String = ""
Dim driveser As String = ""
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", "SELECT * FROM Win32_DiskDrive")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("SerialNumber") <> "" Then driveser = queryObj("SerialNumber")
Debug.Print(queryObj("Model") + ":" + driveser)
Next
Catch err As ManagementException
Debug.Print("An error occurred while querying for WMI data: " & err.Message)
End Try
Namespace :
Imports System.Management
Code:
Dim devid As String = ""
Dim driveser As String = ""
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", "SELECT * FROM Win32_DiskDrive")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("SerialNumber") <> "" Then driveser = queryObj("SerialNumber")
Debug.Print(queryObj("Model") + ":" + driveser)
Next
Catch err As ManagementException
Debug.Print("An error occurred while querying for WMI data: " & err.Message)
End Try
No comments:
Post a Comment