|
-
October 8th, 2008, 10:06 AM
#1
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
-
October 8th, 2008, 10:56 AM
#2
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.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 8th, 2008, 11:10 AM
#3
Re: Checking Hard Disk Serial Number
-
October 8th, 2008, 11:17 AM
#4
Re: Checking Hard Disk Serial Number
 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...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 8th, 2008, 11:28 AM
#5
Re: Checking Hard Disk Serial Number
Hi,
In my computer (XP) it is working Ok.
In other computers (XP) it is not working.
-
October 8th, 2008, 12:33 PM
#6
Re: Checking Hard Disk Serial Number
 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
...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 8th, 2008, 12:58 PM
#7
Re: Checking Hard Disk Serial Number
Hi,
It is not possible, maybe the othe compute is anther country.
-
October 8th, 2008, 01:03 PM
#8
Re: Checking Hard Disk Serial Number
 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).
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 9th, 2008, 01:13 AM
#9
Re: Checking Hard Disk Serial Number
Hi,
Thanks for your advices.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|