yulyos
Well-known member
Hi,
VB2008
Checking Hard Disk Serial Number
The code below Checking the Serial Number of the Hard Disk: FROM Win32_PhysicalMedia
And immediately after it Checking the Serial Number of the Hard Disk: FROM Win32_LogicalDisk
If there is matching the program continue to run, If ther is no matching the program stop to run.
In my computer the program is runing OK.
I checked the code at other computers (Vista and XP).
In Vista when there is a match the code run OK, when there is no match the code collapse.
In XP if there is match or there is no match the code collapse.
To run the code below needs Reference to System.Management
Can someone check the code ?
Thenks in advance
VB2008
Checking Hard Disk Serial Number
The code below Checking the Serial Number of the Hard Disk: FROM Win32_PhysicalMedia
And immediately after it Checking the Serial Number of the Hard Disk: FROM Win32_LogicalDisk
If there is matching the program continue to run, If ther is no matching the program stop to run.
In my computer the program is runing OK.
I checked the code at other computers (Vista and XP).
In Vista when there is a match the code run OK, when there is no match the code collapse.
In XP if there is match or there is no match the code collapse.
To run the code below needs Reference to System.Management
Can someone check the code ?
Thenks in advance
VB.NET:
#Region " Imports "
Imports System
Imports System.IO
Imports System.Management
Imports System.Windows.Forms
#End Region
Public Class Form1
'
#Region " Form1 "
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckHDSN()
End Sub
'
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
MessageBox.Show("Hard Disk Serial Number Matching")
End Sub
#End Region
'
#Region " Private Sub "
Private Sub CheckHDSN()
Me.Cursor = Cursors.WaitCursor
Try
Dim Searcher_P As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_PhysicalMedia")
For Each queryObj As ManagementObject In Searcher_P.Get()
If queryObj("SerialNumber").ToString.Trim = "Y2S0RKFE" Then
Me.Cursor = Cursors.Default
Exit Sub
End If
Next
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: Win32_PhysicalMedia " & ex.Message)
End Try
'
Try
Dim Searcher_L As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'")
For Each queryObj As ManagementObject In Searcher_L.Get()
If queryObj("VolumeSerialNumber").ToString.Trim = "226C1A0B" Then
Me.Cursor = Cursors.Default
Exit Sub
End If
Next
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: VolumeSerialNumber " & ex.Message)
End Try
Me.Cursor = Cursors.Default
MessageBox.Show("Hard Disk Serial Number Not Matching !!!" & vbNewLine & vbNewLine & "Asta La Vista Baby !!!")
End
End Sub
#End Region
'
End Class