473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to detect Hard Disk Serial Number

2
Hi
I want that the user who has registered in my web site download the demo version of software and i have to trace the hard disc serial number of that user and the dsn name of the database with path using asp.net.
So anyone help me?
May 28 '07 #1
2 3082
Hi
I want that the user who has registered in my web site download the demo version of software and i have to trace the hard disc serial number of that user and the dsn name of the database with path using asp.net.
So anyone help me?
Hi,

GetVolumeInformation will return ONLY the volume serial number, which keeps changing on format.

Use the following code to retrieve Model Number, Serial Number and Firmware Revision of a hard disk.

Here by I am providing the Class file code & vb file code.

I am pasting the code of the class file opened by notepad here by
---------------------------------------------------------------
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "HDSN"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

' Antonio Giuliana, 2001-2003

' Costanti per l'individuazione della versione di OS
Private Const VER_PLATFORM_WIN32S = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

' Costanti per la comunicazione con il driver IDE
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088

' Costanti per la CreateFile
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const CREATE_NEW = 1

' Enumerazione dei comandi per la CmnGetHDData
Private Enum HDINFO
HD_MODEL_NUMBER
HD_SERIAL_NUMBER
HD_FIRMWARE_REVISION
End Enum

' Struttura per l'individuazione della versione di OS
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

' Struttura per il campo irDriveRegs della struttura SENDCMDINPARAMS
Private Type IDEREGS
bFeaturesReg As Byte
bSectorCountReg As Byte
bSectorNumberReg As Byte
bCylLowReg As Byte
bCylHighReg As Byte
bDriveHeadReg As Byte
bCommandReg As Byte
bReserved As Byte
End Type

' Struttura per l'I/O dei comandi al driver IDE
Private Type SENDCMDINPARAMS
cBufferSize As Long
irDriveRegs As IDEREGS
bDriveNumber As Byte
bReserved(1 To 3) As Byte
dwReserved(1 To 4) As Long
End Type

' Struttura per il campo DStatus della struttura SENDCMDOUTPARAMS
Private Type DRIVERSTATUS
bDriveError As Byte
bIDEStatus As Byte
bReserved(1 To 2) As Byte
dwReserved(1 To 2) As Long
End Type

' Struttura per l'I/O dei comandi al driver IDE
Private Type SENDCMDOUTPARAMS
cBufferSize As Long
DStatus As DRIVERSTATUS ' ovvero DriverStatus
bBuffer(1 To 512) As Byte
End Type

' Per ottenere la versione del SO
Private Declare Function GetVersionEx _
Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

' Per ottenere un handle al device IDE
Private Declare Function CreateFile _
Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long

' Per chiudere l'handle del device IDE
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long

' Per comunicare con il driver IDE
Private Declare Function DeviceIoControl _
Lib "kernel32" _
(ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
lpInBuffer As Any, _
ByVal nInBufferSize As Long, _
lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, _
lpBytesReturned As Long, _
ByVal lpOverlapped As Long) As Long

' Per azzerare buffer di scambio dati
Private Declare Sub ZeroMemory _
Lib "kernel32" Alias "RtlZeroMemory" _
(dest As Any, _
ByVal numBytes As Long)

' Per copiare porzioni di memoria
Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Declare Function GetLastError _
Lib "kernel32" () As Long

Private mvarCurrentDrive As Byte ' Drive corrente
Private mvarPlatform As String ' Piattaforma usata

Public Property Get Copyright() As String

' Copyright
Copyright = "HDSN Vrs. 1.00, (C) Antonio Giuliana, 2001-2003"

End Property

' Metodo GetModelNumber
Public Function GetModelNumber() As String

' Ottiene il ModelNumber
GetModelNumber = CmnGetHDData(HD_MODEL_NUMBER)

End Function

' Metodo GetSerialNumber
Public Function GetSerialNumber() As String

' Ottiene il SerialNumber
GetSerialNumber = CmnGetHDData(HD_SERIAL_NUMBER)

End Function

' Metodo GetFirmwareRevision
Public Function GetFirmwareRevision() As String

' Ottiene la FirmwareRevision
GetFirmwareRevision = CmnGetHDData(HD_FIRMWARE_REVISION)

End Function

' Proprieta' CurrentDrive
Public Property Let CurrentDrive(ByVal vData As Byte)

' Controllo numero di drive fisico IDE
If vData < 0 Or vData > 3 Then
Err.Raise 10000, , "Illegal drive number" ' IDE drive 0..3
End If

' Nuovo drive da considerare
mvarCurrentDrive = vData

End Property

' Proprieta' CurrentDrive
Public Property Get CurrentDrive() As Byte

' Restituisce drive fisico corrente (IDE 0..3)
CurrentDrive = mvarCurrentDrive

End Property

' Proprieta' Platform
Public Property Get Platform() As String

' Restituisce tipo OS
Platform = mvarPlatform

End Property

Private Sub Class_Initialize()

' Individuazione del tipo di OS
Dim OS As OSVERSIONINFO

OS.dwOSVersionInfoSize = Len(OS)
Call GetVersionEx(OS)
mvarPlatform = "Unk"
Select Case OS.dwPlatformId
Case Is = VER_PLATFORM_WIN32S
mvarPlatform = "32S" ' Win32S
Case Is = VER_PLATFORM_WIN32_WINDOWS
If OS.dwMinorVersion = 0 Then
mvarPlatform = "W95" ' Win 95
Else
mvarPlatform = "W98" ' Win 98
End If
Case Is = VER_PLATFORM_WIN32_NT
mvarPlatform = "WNT" ' Win NT/2000
End Select

End Sub

Private Function CmnGetHDData(hdi As HDINFO) As String

' Rilevazione proprieta' IDE

Dim bin As SENDCMDINPARAMS
Dim bout As SENDCMDOUTPARAMS
Dim hdh As Long
Dim br As Long
Dim ix As Long
Dim hddfr As Long
Dim hddln As Long
Dim s As String

Select Case hdi ' Selezione tipo caratteristica richiesta
Case HD_MODEL_NUMBER
hddfr = 55 ' Posizione nel buffer del ModelNumber
hddln = 40 ' Lunghezza nel buffer del ModelNumber
Case HD_SERIAL_NUMBER
hddfr = 21 ' Posizione nel buffer del SerialNumber
hddln = 20 ' Lunghezza nel buffer del SerialNumber
Case HD_FIRMWARE_REVISION
hddfr = 47 ' Posizione nel buffer del FirmwareRevision
hddln = 8 ' Lunghezza nel buffer del FirmwareRevision
Case Else
Err.Raise 10001, "Illegal HD Data type" ' Altre informazioni non disponibili (Evoluzione futura)
End Select

Select Case mvarPlatform
Case "WNT"
' Per Win NT/2000 apertura handle al drive fisico
hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, _
GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, _
0, OPEN_EXISTING, 0, 0)
Case "W95", "W98"
' Per Win 9X apertura handle al driver SMART
' (in \WINDOWS\SYSTEM da spostare in \WINDOWS\SYSTEM\IOSUBSYS)
' che comunica con il driver IDE
hdh = CreateFile("\\.\Smartvsd", _
0, 0, 0, CREATE_NEW, 0, 0)
Case Else
' Piattaforma non supportata (Win32S)
Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)" ' Altre piattaforme non gestite
End Select
' Controllo validità handle
If hdh = 0 Then
Err.Raise 10003, , "Error on CreateFile"
End If

' Azzeramento strutture per l'I/O da driver
ZeroMemory bin, Len(bin)
ZeroMemory bout, Len(bout)

' Preparazione parametri struttura di richiesta al driver
With bin
.bDriveNumber = mvarCurrentDrive
.cBufferSize = 512
With .irDriveRegs
If (mvarCurrentDrive And 1) Then
.bDriveHeadReg = &HB0
Else
.bDriveHeadReg = &HA0
End If
.bCommandReg = &HEC
.bSectorCountReg = 1
.bSectorNumberReg = 1
End With
End With

' Richiesta al driver
DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, _
bin, Len(bin), bout, Len(bout), br, 0

' Formazione stringa di risposta
' da buffer di uscita
' L'ordine dei byte e' invertito
s = ""
For ix = hddfr To hddfr + hddln - 1 Step 2
If bout.bBuffer(ix + 1) = 0 Then Exit For
s = s & Chr(bout.bBuffer(ix + 1))
If bout.bBuffer(ix) = 0 Then Exit For
s = s & Chr(bout.bBuffer(ix))
Next ix

' Chiusura handle
CloseHandle hdh

' Restituzione informazione richiesta
CmnGetHDData = Trim(s)

End Function

--------------------------------------------------------------------------

In the form, place a combobox with values 0,1,2,3 representing Primary Master, Primary Slave, Secondary Master & Secondary Slave HDDs respectively.

Code is
-----------------
Dim h As HDSN

Private Sub cmdGo_Click()

Dim hT As Long
Dim uW() As Byte
Dim dW() As Byte
Dim pW() As Byte

Set h = New HDSN

With h
.CurrentDrive = Val(cbDrive.Text)

lstInfo.Clear
lstInfo.AddItem "Current drive: " & .CurrentDrive
lstInfo.AddItem ""
lstInfo.AddItem "Model number: " & .GetModelNumber
lstInfo.AddItem "Serial number: " & .GetSerialNumber
lstInfo.AddItem "Firmware Revision: " & .GetFirmwareRevision
lstInfo.AddItem ""
lstInfo.AddItem "Copyright: " & .Copyright
End With

Set h = Nothing

End Sub

Private Sub Form_Load()
cbDrive.ListIndex = 0
End Sub

--------------------------------------------------------------------
Hope this will help you...
Thanks
Raj
Dec 12 '07 #2
Plater
7,872 Expert 4TB
You can also use WMI to gather the information you want, along with other information you might find useful to uniquly identify someone.
Dec 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Stephane Belzile | last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS unit in case of power failure? Thanks
1
by: Ahmed Essa | last post by:
hiiiiiiiiiii, i have aproblem in System.management namespace which use to get the serial number of hard disk. my problem is that when i run my application on windows2000 server it cause execption...
3
by: Arne Beruldsen | last post by:
How do you read the serial number to a hard drive? Thanks...Arne
3
by: abeer el ashker | last post by:
how can i get serial numper of hard disk using api
14
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
1
by: alfred | last post by:
Hi How can I determine what the hard disk and or cpu's identification (serial no.) is. thanks Alfred
6
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
7
by: Adele le Roux | last post by:
Hi All, How can I get the hard disk serial number of a remote computer's C:? The drive will NOT be mapped as a network drive. Thanks, Adele
0
by: preethaAjayan | last post by:
Could anybody please help me with a piece of code to get hard disk's serial number using C#, not volume serial number, actual number that manufactures give to hard disks.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.