Introduction

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.

Background

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:

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.

If you are stuck with a non .NET compiler, you could still use the source code from UnmanagedCode.cpp, just uncomment the #define NATIVE_CODEline.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 release.zip archive, since they are 32 bit for Windows XP.

History

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.

Comments and Discussions

Sir, when I am compiling the DLL, the size of the driveinfoex.dll is 108 KB as I have not change any line of given source code...and your file size for DriveInfoEx.dll is only 76 KB ...
Why this difference has been occured? or please give me some of ideas for compiling this DLL to reduce the size from 108 KB...

I downloaded the source code, i did a build of the whole soln, i wnat to make use of the dll only. i have a seperate application where in i want to use this dll . I am using VS2005 and framework is 2.0.

i get a error saying the assembly requires a string name. can you please suggest here what to do ?

[...i get a error saying the assembly requires a string name]
Do you mean strong name?
If that is the case, than you have to sign the dll and that requires recompilation or using the signing tool from the SDK.

There is no silver bullet for protection.
Even my solution is vulnerable at the driver level.
There are other solutions with registry values, key files or some windows service acting as a License manager.
You can search about them online.

for the C#->VB.net project convertionyou can try http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB.htm[^]. Or you can try Lutz's reflector with the appropriate plugin.
Converting the unmanaged C++ to vb.net is not possible as I know it, so driveinfoex.dll requires a rewrite and a lot of PInvoke calls to do the same win32 Api calls.
I don't plan to update this dll in the near future.

In your development of this utility and exploration of the DeviceIoControl API, did you come across any available information as to whether the HDD power-on password is set (not to be confused with the several BIOS passwords that can be set)?