Click here to Skip to main content
13,148,573 members (53,085 online)
Click here to Skip to main content
Add your own
alternative version


176 bookmarked
Posted 29 Dec 2006

Get Physical HDD Serial Number without WMI

, 6 May 2008
Rate this:
Please Sign up or sign in to vote.
Retrieve the physical Hard drive ID and other info using low level APIs like DeviceIOControl

Sample Image - DriveInfo.png


Many people looking for a schema to protect their work need to get some information that is hardware specific like the Mac Address or some hard drive serial number.


If you tried other solutions like like this one, it probably did not work for you because it's using the WMI services. I was able to find a solution that worked reasonably well here. It made low level calls to the disk using commands sent by the DeviceIoControl API. The code was not very reusable unless you used native C++. Therefore I brushed it a bit and made it look more Object Oriented. Most importantly, I exposed the drive information through a .NET collection.

Using the Code

Since the collection is written in MC++, I've included some Microsoft DLLs from the redistributable pack in the demo zip. Also it's mandatory to use .NET 2.0 since the collection is generic.

The code is very easy to use from any .NET language, like C# for instance:

m_list = new DriveListEx();
//bind to a a grid view
m_dataGridView.DataSource = m_list;

Points of Interest

The information about the internal drives is gathered in DiskInfo::LoadDiskInfo();

DiskInfo is a native singleton class that wraps the calls to ReadPhysicalDriveInNTWithAdminRights() and ReadIdeDriveAsScsiDriveInNT(). I ignored the ReadPhysicalDriveInNTWithZeroRights() that did not seem to work anyways.

Both functions will call AddIfNew() if they can retrieve the information.

Internally there is a list that holds the raw information about the drives and that is updated when a new drive information was found.

BOOL DiskInfo::AddIfNew(USHORT *pIdSector)
  BOOL bAdd = TRUE;
  for(UINT i =0; i< m_list.size();i++)
    if(memcmp(pIdSector,m_list[i],256 * sizeof(WORD)) == 0)
       bAdd = false;
      WORD* diskdata = new WORD[256];
  return bAdd;

If you are stuck with a non .NET compiler, you could still use the source code from UnmanagedCode.cpp, just uncomment the #define NATIVE_CODE line.
This build is for Windows XP 32 bit systems. If you need it for Vista or 64 bit systems, you should select the right include and lib folders when building and should not use the additional DLLs from the archive, since they are 32 bit for Windows XP.


  • Version 1.1: Added ReadPhysicalDriveInNTUsingSmart for reading the HDD info.
    P.S. I did not get a chance to test it for Windows 95 and alike.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
United States United States
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Member 1272333412-Apr-17 8:56
memberMember 1272333412-Apr-17 8:56 
QuestionDoes not work with VS2013 Pin
Matias Castro7-Feb-17 16:00
memberMatias Castro7-Feb-17 16:00 
QuestionYour solution is sh*t... Pin
JoeDude12328-Mar-16 17:45
memberJoeDude12328-Mar-16 17:45 
QuestionDownload Link Pin
LoganMB20-Jul-15 10:05
memberLoganMB20-Jul-15 10:05 
QuestionThe downloads doesn't work well! Pin
jjjjj1023102324-Jun-15 20:06
memberjjjjj1023102324-Jun-15 20:06 
AnswerRe: The downloads doesn't work well! Pin
Member 1184242720-Jul-15 9:55
memberMember 1184242720-Jul-15 9:55 
QuestionGetting Error: Could not load file or assembly 'DriveInfoEx, Version=1.1.3054.15437, Culture=neutral Pin
Mohiyuddin Khan28-May-14 19:19
memberMohiyuddin Khan28-May-14 19:19 
AnswerRe: Getting Error: Could not load file or assembly 'DriveInfoEx, Version=1.1.3054.15437, Culture=neutral Pin
dmihailescu1-Jul-14 3:44
memberdmihailescu1-Jul-14 3:44 
QuestionCan not run This Code In VS2010 Pin
Yonos allahyari19-Dec-13 8:31
memberYonos allahyari19-Dec-13 8:31 
AnswerRe: Can not run This Code In VS2010 Pin
Albert Holguin19-Dec-13 9:16
memberAlbert Holguin19-Dec-13 9:16 
AnswerRe: Can not run This Code In VS2010 Pin
Albert Holguin19-Dec-13 9:32
memberAlbert Holguin19-Dec-13 9:32 
QuestionCan i get usb drive serial no from this code Pin
sandeepraj331-Dec-13 21:51
membersandeepraj331-Dec-13 21:51 
QuestionDriveInfoEx.dll not working for x64 bit computer Pin
kalaivanan from Bangalore, India22-Oct-13 3:57
memberkalaivanan from Bangalore, India22-Oct-13 3:57 
AnswerRe: DriveInfoEx.dll not working for x64 bit computer Pin
dmihailescu23-Oct-13 15:30
memberdmihailescu23-Oct-13 15:30 
GeneralRe: DriveInfoEx.dll not working for x64 bit computer Pin
Hossam™ Ahmed11-Feb-15 1:27
memberHossam™ Ahmed11-Feb-15 1:27 
Suggestioni tried ur demo project Pin
abhinav_8930-Aug-13 7:22
memberabhinav_8930-Aug-13 7:22 
GeneralRe: i tried ur demo project Pin
dmihailescu1-Jul-14 3:46
memberdmihailescu1-Jul-14 3:46 
QuestionHow to execute this code Pin
Member 101775611-Aug-13 10:40
memberMember 101775611-Aug-13 10:40 
BugNot runing in VS2008 Pin
Menon Santosh13-Mar-13 2:28
memberMenon Santosh13-Mar-13 2:28 
GeneralRe: Not runing in VS2008 Pin
dmihailescu23-Oct-13 15:39
memberdmihailescu23-Oct-13 15:39 
Questioni want to get hd Info of other computer through network Pin
ehtshamkh15-Jan-13 1:20
memberehtshamkh15-Jan-13 1:20 
QuestionIf there are more than 1 HDD? Pin
leomifare21-Oct-12 21:20
memberleomifare21-Oct-12 21:20 
Questionmac add, ip add, motherboard serial no, processor, local drive Pin
Praveen S22-Jul-12 20:38
memberPraveen S22-Jul-12 20:38 
GeneralMy vote of 5 Pin
Nox PasNox11-May-12 4:43
memberNox PasNox11-May-12 4:43 
Answeranother method Pin
y_sir9-May-12 23:06
membery_sir9-May-12 23:06 
GeneralMy vote of 5 Pin
Amir Dashti16-Feb-12 4:08
memberAmir Dashti16-Feb-12 4:08 
QuestionHow to get HDD Device Driver without WMI? Pin
Holt24517-Dec-11 15:29
memberHolt24517-Dec-11 15:29 
Question[My vote of 1] Code from WinSim Inc. Pin
_DiZ29-Nov-11 6:45
member_DiZ29-Nov-11 6:45 
AnswerRe: [My vote of 1] Code from WinSim Inc. Pin
dmihailescu29-Nov-11 16:14
memberdmihailescu29-Nov-11 16:14 
GeneralMy vote of 2 Pin
zomorrod.company14-Nov-11 1:18
memberzomorrod.company14-Nov-11 1:18 
GeneralRe: My vote of 2 Pin
dmihailescu29-Nov-11 16:19
memberdmihailescu29-Nov-11 16:19 
QuestionDrive letter Pin
edy_3dz9-Aug-11 10:04
memberedy_3dz9-Aug-11 10:04 
Generaldriveinfoex.dll requires administrator rights in win 7 - how to solve it Pin
nileshrajkot22-Apr-11 20:38
membernileshrajkot22-Apr-11 20:38 
GeneralMy vote of 4 Pin
nileshrajkot22-Apr-11 20:34
membernileshrajkot22-Apr-11 20:34 
GeneralVery nice............It has get me out of My very hard problem....... Pin
Pritesh Aryan15-Apr-11 2:30
memberPritesh Aryan15-Apr-11 2:30 
GeneralSorry, i'm a noob Pin
blthbllala18-Jan-11 11:17
memberblthbllala18-Jan-11 11:17 
GeneralMy vote of 2 Pin
Member 164379218-Dec-10 5:01
memberMember 164379218-Dec-10 5:01 
GeneralRe: My vote of 2 Pin
dmihailescu29-Nov-11 16:21
memberdmihailescu29-Nov-11 16:21 
GeneralSerial ID RAID Pin
big_buka12-Dec-10 21:13
memberbig_buka12-Dec-10 21:13 
Generalworks with Win7 x86 not working with xp Pin
Member 437972011-Nov-10 1:46
memberMember 437972011-Nov-10 1:46 
GeneralRe: works with Win7 x86 not working with xp Pin
nethsu28-Nov-10 21:54
membernethsu28-Nov-10 21:54 
GeneralREAL Hard disk serial number Pin
hingman3-Nov-10 20:50
memberhingman3-Nov-10 20:50 
GeneralRe: REAL Hard disk serial number Pin
DizZ11-Jan-11 3:54
memberDizZ11-Jan-11 3:54 
GeneralRe: REAL Hard disk serial number Pin
hingman11-Jan-11 16:38
memberhingman11-Jan-11 16:38 
GeneralMy vote of 5 Pin
Archit937328444829-Oct-10 19:33
memberArchit937328444829-Oct-10 19:33 
GeneralUnable to run on 64 bit Pin
ilke ALTINPULLUK26-Oct-10 4:12
memberilke ALTINPULLUK26-Oct-10 4:12 
Questioncan we write this with c sharp Pin
nethsu24-Oct-10 23:47
membernethsu24-Oct-10 23:47 
AnswerRe: can we write this with c sharp Pin
dmihailescu26-Oct-10 16:23
memberdmihailescu26-Oct-10 16:23 
GeneralRe: can we write this with c sharp Pin
nethsu26-Oct-10 17:06
membernethsu26-Oct-10 17:06 
GeneralNot Work with Framework 4.0 Pin
kalpesh280428-Sep-10 22:46
memberkalpesh280428-Sep-10 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 6 May 2008
Article Copyright 2006 by dmihailescu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid