Checking Hard Disk Serial Number
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
Code:
#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
Re: Checking Hard Disk Serial Number
Why not just step through it with the debugger on the XP system and see that is being returned. :confused: :confused: :confused:
Re: Checking Hard Disk Serial Number
Re: Checking Hard Disk Serial Number
Quote:
Originally Posted by yulyos
Hi,
Pleas try the code.
That would be pointless. Obviously it is something to do with YOUR environment and/or YOUR program.
Again I will ask, what are the values returned by the API calls on YOUR system. It is a simple debugging task...
Re: Checking Hard Disk Serial Number
Hi,
In my computer (XP) it is working Ok.
In other computers (XP) it is not working.
Re: Checking Hard Disk Serial Number
Quote:
Originally Posted by yulyos
Hi,
In my computer (XP) it is working Ok.
In other computers (XP) it is not working.
1) So debug it on the computer where it is not working.
2) Why would you exprect it to work when you have hard coded values....
Code:
...
If queryObj("SerialNumber").ToString.Trim = "Y2S0RKFE" Then
...
If queryObj("VolumeSerialNumber").ToString.Trim = "226C1A0B" Then
...
Re: Checking Hard Disk Serial Number
Hi,
It is not possible, maybe the othe compute is anther country.
Re: Checking Hard Disk Serial Number
Quote:
Originally Posted by yulyos
Hi,
It is not possible, maybe the othe compute is anther country.
Then you have three options:
1) Include proper diagnostics and logging features in your program. This should be done for any program which is going to be distributed.
2) Use Remote Debugging Capabilities build into Visual Studio
3) Remote access the machine (either Remote Desktop, Remote Assistance, or 3rd party application such as SignMeIn, or GoToMyPC).
Re: Checking Hard Disk Serial Number
Hi,
Thanks for your advices.