E
Eekhay
Guest
Hi All,
I'm trying working around with this code to read the removable drive serial number. This code work fine for all drives which directly attached to the computer, however it not work for the drive attached through external device like Card Read or USB HUB.
I'm looking for help and guidance to work on this code to able to read the removable drive serial number which attached through the external device.
Here is the code I'm currently working on:
Public Class frmGetDriveSerialNumber
Private Function GetDriveSerialNumber(ByVal intDriveNumber As Integer) As String
Dim objWMIService As Object, _
colItems As Object, _
objItem As Object, _
strDrive As String, _
strComputer As String
strDrive = "\\\\.\\PHYSICALDRIVE" & intDriveNumber
On Error Resume Next
strComputer = "."
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMedia Where Tag = '" & strDrive & "'", , 16)
'Set objItem = colItems.Item(strKey)
For Each objItem In colItems
GetDriveSerialNumber = Trim(objItem.SerialNumber)
Next
objItem = Nothing
colItems = Nothing
objWMIService = Nothing
End Function
Private Sub btnReadSN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSN.Click
lblDisk1.Text = GetDriveSerialNumber(1)
lblDisk2.Text = GetDriveSerialNumber(2)
lblDisk3.Text = GetDriveSerialNumber(3)
lblDisk4.Text = GetDriveSerialNumber(4)
lblDisk5.Text = GetDriveSerialNumber(5)
lblDisk6.Text = GetDriveSerialNumber(6)
lblDisk7.Text = GetDriveSerialNumber(7)
lblDisk8.Text = GetDriveSerialNumber(8)
lblDisk9.Text = GetDriveSerialNumber(9)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class
Appreciate and Thanks.
Continue reading...
I'm trying working around with this code to read the removable drive serial number. This code work fine for all drives which directly attached to the computer, however it not work for the drive attached through external device like Card Read or USB HUB.
I'm looking for help and guidance to work on this code to able to read the removable drive serial number which attached through the external device.
Here is the code I'm currently working on:
Public Class frmGetDriveSerialNumber
Private Function GetDriveSerialNumber(ByVal intDriveNumber As Integer) As String
Dim objWMIService As Object, _
colItems As Object, _
objItem As Object, _
strDrive As String, _
strComputer As String
strDrive = "\\\\.\\PHYSICALDRIVE" & intDriveNumber
On Error Resume Next
strComputer = "."
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMedia Where Tag = '" & strDrive & "'", , 16)
'Set objItem = colItems.Item(strKey)
For Each objItem In colItems
GetDriveSerialNumber = Trim(objItem.SerialNumber)
Next
objItem = Nothing
colItems = Nothing
objWMIService = Nothing
End Function
Private Sub btnReadSN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSN.Click
lblDisk1.Text = GetDriveSerialNumber(1)
lblDisk2.Text = GetDriveSerialNumber(2)
lblDisk3.Text = GetDriveSerialNumber(3)
lblDisk4.Text = GetDriveSerialNumber(4)
lblDisk5.Text = GetDriveSerialNumber(5)
lblDisk6.Text = GetDriveSerialNumber(6)
lblDisk7.Text = GetDriveSerialNumber(7)
lblDisk8.Text = GetDriveSerialNumber(8)
lblDisk9.Text = GetDriveSerialNumber(9)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class
Appreciate and Thanks.
Continue reading...