Click to See Complete Forum and Search --> : Checking Hard Disk Serial Number


yulyos
October 8th, 2008, 10:06 AM
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

#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

TheCPUWizard
October 8th, 2008, 10:56 AM
Why not just step through it with the debugger on the XP system and see that is being returned. :confused: :confused: :confused:

yulyos
October 8th, 2008, 11:10 AM
Hi,

Pleas try the code.

TheCPUWizard
October 8th, 2008, 11:17 AM
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...

yulyos
October 8th, 2008, 11:28 AM
Hi,

In my computer (XP) it is working Ok.
In other computers (XP) it is not working.

TheCPUWizard
October 8th, 2008, 12:33 PM
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....


...
If queryObj("SerialNumber").ToString.Trim = "Y2S0RKFE" Then
...
If queryObj("VolumeSerialNumber").ToString.Trim = "226C1A0B" Then
...

yulyos
October 8th, 2008, 12:58 PM
Hi,

It is not possible, maybe the othe compute is anther country.

TheCPUWizard
October 8th, 2008, 01:03 PM
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).

yulyos
October 9th, 2008, 01:13 AM
Hi,

Thanks for your advices.