Welcome to AddressOf.com Sign in | Join | Help

Determine Hard Drive Serial Numbers

Thanks to James Avery for pointing out an article on CodeProject on how to determine drive serial numbers using WMI in C#.  Ported it to VB.NET and VB.NET'ised it a bit.

Download

[update] Also, be sure to check out The Revenge of DriveInfo.

Published Saturday, February 14, 2004 2:25 AM by CorySmith
Filed under:

Comments

# re: Determine Hard Drive Serial Numbers

Saturday, February 14, 2004 4:45 PM by Mike
Have you looked into just how unique the manufacturer serial # is? I mean I'm sure it's unique within a particular manufacturer but what about globally unique?

# re: Determine Hard Drive Serial Numbers

Saturday, February 14, 2004 6:10 PM by Cory Smith
If your concerned about uniqueness, you could use a combination of the model name and the serial number. This way you guarentee that you won't run into different mfg using the same serial number.

Also, I'm exploring this topic a little further and there seems to be some severe limitations in the usage of drive serial numbers. So far, it looks to be reliable for the primary ide controller, however, the secondary is not returning serial numbers (at least not on my machine).

Since I'm pretty much focused on Windows 2000 and greater, I'm looking at another option. As soon as I have it figured out, I'll post my results. It's not using WMI, but rather going directly to P/Invoke Win32 methods. So far, it looks like it will have the same security restrictions as the WMI method, but should be a lot faster and looks to be more reliable for returning a serial number.

# Revenge Of DriveInfo (Drive Serial Numbers)

Saturday, February 14, 2004 8:37 PM by AddressOf.com

# re: Determine Hard Drive Serial Numbers

Friday, February 11, 2005 12:39 AM by S373N
i tried with windows 9X and it won't return serial numbers.

# re: Determine Hard Drive Serial Numbers

Saturday, April 30, 2005 3:49 AM by Vitoto
Hi, you know how get ID the Motherboard, CPUID ??

I need 3 IDs for identify client.

Mac Address is not good, they can Spoffing Mac or Chance Red Card, not much cost.

# re: Determine Hard Drive Serial Numbers

Saturday, April 30, 2005 3:49 AM by Vitoto
Hi, you know how get ID the Motherboard, CPUID ??

I need 3 IDs for identify client.

Mac Address is not good, they can Spoffing Mac or Chance Red Card, not much cost.

# re: Determine Hard Drive Serial Numbers

Tuesday, August 9, 2005 5:23 AM by viral
how can i get the mother board and hard drive serial number

# re: Determine Hard Drive Serial Numbers

Tuesday, August 9, 2005 5:26 AM by viral
how can i get the mother board and hard drive serial number?
reply me on viraljan10@yahoo.com
thanks viral

# re: Determine Hard Drive Serial Numbers

Wednesday, September 28, 2005 10:48 AM by Madhavi
Hi ,
Its not working for me.
I will try ,
but will it work on win 9x ?
plz keep contact
Its may id
madhavi.patil@sixcube.com
madhavi_mcs2004@yahoo.co.in

I will be very happy to get your reply
Thanks and Regards
Madhavi

# re: Determine Hard Drive Serial Numbers

Wednesday, October 5, 2005 1:40 PM by 游戏下载
how can i get the mother board and hard drive serial number?

# re: Determine Hard Drive Serial Numbers

Thursday, October 6, 2005 1:10 PM by Cory Smith
Please see the Gathering computer information using WMI (http://addressof.com/blog/archive/2005/10/06/8486.aspx) example for how to read mother board, cpu and bios information.

# re: Determine Hard Drive Serial Numbers

Monday, November 7, 2005 11:55 AM by rezaei
cpu and motherboard serial numbers

# re: Determine Hard Drive Serial Numbers

Tuesday, November 22, 2005 8:10 AM by ahmed3essa
hiiiiiiiiiiiiiiiiiiiiiiiiiiiii,
i use system.management namespace to get the serial number of hard disk but the application work on winxp and don't work on win2000 server,
plz if you have the solution of this problem send me quickly.

ahmed3essa
thanks

# re: Determine Hard Drive Serial Numbers

Wednesday, December 7, 2005 11:58 AM by Vitoto
Function GUID() As String

GUID = System.GUID.NewGuid().ToString()

End Function

A GUID is a 128-bit integer (16 bytes) that you can use across all computers and networks wherever a unique identifier is required. There's a very low probability that this type of identifier will be duplicated.

# re: Determine Hard Drive serial number

Saturday, February 18, 2006 7:57 AM by IRSHAD
HOW TO READ THE SERIAL NUMBER OF HARD DISK NOT DISK DRIVE, MOTHERBOARD, PROCESSOR AND RAM USING VISUAL BASIC 6.0 CODE

# re: Determine Hard Drive Serial Numbers

Saturday, March 18, 2006 3:07 AM by Siraj Ultimatelogics
HOW TO READ THE SERIAL NUMBER OF HARD DISK NOT DISK DRIVE, MOTHERBOARD, PROCESSOR AND RAM USING VISUAL BASIC 6.0 CODE

# Mr

Wednesday, April 12, 2006 8:11 AM by Muhammad Ilyas
Please tell me simplest code in vb6 to read hard disk serial number and modal number.

thanks

# re: Determine Hard Drive Serial Numbers

Tuesday, May 16, 2006 9:04 AM by Ryan Turnerr
I think a combination of the at least 2 ID's (HD, MB or MAC) should be sufficient. I realize the issues with each type of ID individually, but combined they should be pretty bullet proof.

# re: Determine Hard Drive Serial Numbers

Friday, June 16, 2006 8:18 AM by rohan pawaskar
i need the hard disc number but not volume number and the motherboard serial number. please mail me the code.

# re: Determine Hard Drive Serial Numbers

Wednesday, July 5, 2006 4:54 AM by Ebin Roy
Hi guys ,
Try this

Declare Function GetHDDSerialId Lib "HardDiskInfoV1.dll" () As String
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Public function SetHardDiskID()as string
dim gHardDiskId as string
Dim flNumber As Long = LoadLibrary ("HardDiskInfoV1.dll")
gHardDiskId = GetHDDSerialId

If Asc(Right(gHardDiskId, 1)) = 0 Then
gHardDiskId = Trim(Mid(gHardDiskId, 1, Len(gHardDiskId) - 1))
Else
gHardDiskId = Trim(gHardDiskId)
End If
return gHardDiskId

End function

# re: Determine Hard Drive Serial Numbers

Wednesday, July 12, 2006 3:01 AM by butengorg
hi i want hard disk serial number but not vollume number of the drives...i need code in preferably java...

# re: Determine Hard Drive Serial Numbers

Wednesday, November 15, 2006 4:28 PM by cnnix

Hello World!

I'm a new user of Extreme-B and I'm ery sorry for my English, but I need help.

Could I read the serial number of an hard disk in isual basic?

A kiss from Italy,

Massimiliano

isual Basic Programming, SQL Serer, Windows NT, Microsoft Access and many more!I meet the problem long time ago and got some solutions.

Although it doesn't meet my requirement, it may be useful to you.

There are some DLL or CONTROLs(OCX) can easily got the serial No of HD. Such as LONSSOFT DISKSERIAL CONTROL(Shareware, will popup a dialog box if unregistered), hwinfo.ocx(Free, but may need another 2 dll to run in some PC, also can get much more info about the PC), harddisksn.dll(Not so easy to use and distribute your Prog. but I hae example code in B)

If you are interested in such files aboe, please let me know which, when and how.

BTW, I'm also a "Newcomer" of English, Chinese is my mother tongue, hehe......

# re: Determine Hard Drive Serial Numbers

Friday, November 24, 2006 9:00 PM by Saiful Islam Sumon

Thanks.

# re: Determine motherboard Serial Numbers

Monday, January 8, 2007 12:30 PM by Rams

i need code for find mother board serial no using vb.net

# re: Determine Hard Drive Serial Numbers

Friday, January 19, 2007 5:44 PM by Mauricio

i need the hard disc number but not volume number and the motherboard serial number for visual basic 6. please mail me the code. My email es mauricio_ols@yahoo.com

# code in vb 6 to determine Hard Drive Serial Numbers

Thursday, February 1, 2007 11:31 PM by srs

how can i get hdd serial no. using vb 6.0. plz help me.

# re: Determine Hard Drive Serial Numbers

Thursday, June 21, 2007 11:37 PM by Azizul Haq
I want VB 6 coding to get Hard disk serial number and modle number.

# re: Determine Hard Drive Serial Numbers

Friday, August 24, 2007 10:59 PM by prabha
hi, i need a help. how can i get hdd serial no. using c#.net plz help me.

# re: Determine Hard Drive Serial Numbers

Thursday, September 6, 2007 5:22 AM by andrasg
yea - thanks to WGA of MS there's a quite easy way, using the registry You find the HD Serial, all MAC Adresses and another identifier here: HKLM\Software\Microsoft\Windows Genuine Advantage\ can be read in VC++ with the API32 function RegOpenKey() or RegOpenKeyEx() in Borland by the tRegistry Object But these entries only exist after running the WGA at least once.

# re: Determine Hard Drive Serial Numbers

Sunday, September 23, 2007 9:35 PM by Tareq
You can find easily c#.net code from this link http://www.eggheadcafe.com/articles/20021019.asp . you can also download code & for .net 2005 the downloaded code should be convert

# rre: Determine Hard Drive Serial Numbers

Sunday, November 18, 2007 4:28 AM by Ebin Roy
HardDiskInfoV1.dll

# re: Determine Hard Drive Serial Numbers

Wednesday, December 12, 2007 3:24 AM by Rajkumar GS
Hi, One of best way to configure a tool to run only on a particular machine is using the MANUFACTURER SERIAL NUMBER OF THE HARD DISK, which is unique. 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 represents Primary Master, Primary Slave, Secondary Master & Secondary Slave HDDs. 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
Anonymous comments are disabled