Can anyone tell me how to read the Hard Disk Serial Number as well as the volume number...
reading hard disk number
Started by veda87, Aug 31 2009 10:33 PM
11 replies to this topic
#1
Posted 31 August 2009 - 10:33 PM
|
|
|
#2
Posted 01 September 2009 - 03:30 AM
hi its easy to be done in .NET
for motherboard
for motherboard
Public Function GetMotherboardSerialNumber() As String Dim searcher As New System.Management.ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard") For Each obj As System.Management.ManagementObject In searcher.Get Return obj.Properties("SerialNumber").Value.ToString Next Return String.Empty
End Function
for hard disk
#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
#3
Posted 01 September 2009 - 05:07 AM
can anyone explain me that code....
#4
Posted 01 September 2009 - 05:50 AM
Before attempting to explain that code:
What operating system?
C or C++?
Does it have to be in a program, or are you willing to use other methods?
What operating system?
C or C++?
Does it have to be in a program, or are you willing to use other methods?
#5
Posted 01 September 2009 - 07:16 AM
WingedPanther said:
Before attempting to explain that code:
What operating system?
C or C++?
Does it have to be in a program, or are you willing to use other methods?
What operating system?
C or C++?
Does it have to be in a program, or are you willing to use other methods?
I would like to do a program in C... i am using linux operating system...
C or C++ both are comfortable...
#6
Posted 01 September 2009 - 08:04 AM
Ignore mH_portal's post, then.
From the command line: hdparm -i /dev/hda
From the command line: hdparm -i /dev/hda
#7
Posted 01 September 2009 - 08:05 AM
it not a C++ or C Source code , its based on .NET
by the way you can use .net source under linux environment
take a look at it
codeproject.com/KB/mcpp/DriveInfoEx.aspx
by the way you can use .net source under linux environment
take a look at it
codeproject.com/KB/mcpp/DriveInfoEx.aspx
#8
Posted 01 September 2009 - 08:10 AM
WingedPanther said:
Ignore mH_portal's post, then.
From the command line: hdparm -i /dev/hda
From the command line: hdparm -i /dev/hda
when i used this command... it says
/dev/hda: No such file or directory
But i got it in command line: sudo lshw -C disk | grep serial
But what about as a C program... Can't we get it using a C program... What about for windows operating system
#9
Posted 01 September 2009 - 09:24 AM
hdparm is a command line utility for the Linux and Windows OS to set and view SATA & IDE hard disk hardware parameters.
be careful about what kinda hard disk do you have ? sata or ide
if you have ide your disk drives it would be like that: hda1 hda2 hda3 under linux
or if you have SATA disk drives it would be like that: sda1 , sda2 , so on
some distribution wont mount hard drives automatically, you have to mount your drives before working with them.
i think its not necessary to write a C app for it , write a bash file to save the serial number in a Txt file.
for windows app , i gave u the source that you need to compile in .NET
hdparm for windows :
hdparm-win32.dyndns.org/hdparm/
hdparm for linux :
sourceforge.net/projects/hdparm/
be careful about what kinda hard disk do you have ? sata or ide
if you have ide your disk drives it would be like that: hda1 hda2 hda3 under linux
or if you have SATA disk drives it would be like that: sda1 , sda2 , so on
some distribution wont mount hard drives automatically, you have to mount your drives before working with them.
i think its not necessary to write a C app for it , write a bash file to save the serial number in a Txt file.
for windows app , i gave u the source that you need to compile in .NET
hdparm for windows :
hdparm-win32.dyndns.org/hdparm/
hdparm for linux :
sourceforge.net/projects/hdparm/
#10
Posted 01 September 2009 - 09:40 AM
You can get it using a C program, but the question becomes: what are you trying to do with it?
#11
Posted 01 September 2009 - 09:55 AM
i think that its better get your hands abit mix up with Code
i can suggest a trick to use C language to gain serial number ,
you know how to retrieve serial number via terminal , now you can use system function in C , like
system("hdparm /dev/hda0/",ret_var);
then extract the serial number portion from ret_Var
i can suggest a trick to use C language to gain serial number ,
you know how to retrieve serial number via terminal , now you can use system function in C , like
system("hdparm /dev/hda0/",ret_var);
then extract the serial number portion from ret_Var
#12
Posted 02 September 2009 - 04:36 AM
What system() function are you using? system() only takes one argument.
system(3): execute shell command - Linux man page
You might want to look into stat(), though.
stat(2): file status - Linux man page
system(3): execute shell command - Linux man page
You might want to look into stat(), though.
stat(2): file status - Linux man page
sudo rm -rf /


Sign In
Create Account


Back to top









