Source : http://www.techblog.tomksoft.com/programming/hardware-serial-number-generator.html

One of my applications had to encrypt very secret informations on user's computer.
I thought that asking user for password would be foolish, because it's easier to get the password from user than crack encrypted data.
All I've needed was unit/code that generates unique identificator for a computer.
I've spent many hours searching for it, but without results.
So, I've decided to create my own hardware serial number generator.

Ingredients list

  • Delphi 5/6/7/2005/2006
  • Magenta WMI - gives access to WMI - the most complete informations source in Windows
  • MD5 unit - you can also use DCPcrypt's MD5 unit

Requirements

  • Windows 2000,Windows XP or higher (it may also work on older Windows versions, but you'll have to install WMI Host)
  • Small Delphi experience

The work

So, idea is simply - get as many as possible informations that are constant and uniqe, for example BIOS Name or processor id.
My generator uses:

  • Motherboard name
  • Windows serial number
  • Windows installation date
  • Processor id
  • Bios id
  • All disks' serial numbers
  • All disks' models

Where to use?

It has many uses - it can be used in licensing systems, encryption, banning etc.
You should try it with DCPcrypt.

The code

Motherboard name:
Result := MagWmiGetBaseBoard;

Windows serial number:
Result := MagWmiGetOSInfo(‘SerialNumber’);

Windows installation date:
Result := MagWmiGetOSInfo(‘InstallDate’);

Processor ID:
Result := MagWmiGetProcInfo(‘ProcessorID’);

Bios ID:
uses Registry;

function BiosID : string;
var
WinReg : TRegistry;
Buffer : PChar;
Retvar : String;
begin
try
WinReg := TRegistry.Create;
WinReg.RootKey := HKEY_LOCAL_MACHINE;
if WinReg.OpenKeyReadOnly(‘\HARDWARE\DESCRIPTION\System’) then
begin
GetMem(Buffer,$2000);
WinReg.ReadBinaryData(‘SystemBiosVersion’,Buffer^,$2000);
RetVar := WinReg.ReadString(‘Identifier’) + ‘ ‘ + Buffer;
FreeMem(Buffer);
end;
finally
WinReg.Free;
end;
Result := Retvar;
end;

Disks’ serial numbers:
Result := MagWmiGetDiskSerial(DiskIndex);

Disks’ models:
Result := MagWmiGetDiskModel(DiskIndex);

Example

Here’s my computer’s hardware serial number and informations that were used to generate it:
Hardware serial number ingredients:
ASUSTeK Computer INC. A7N8X-E
55034-642-5926024-XXXXX
20051110171825.000000+060
0383FBFF0000XXXX
AT/AT COMPATIBLE Nvidia - 42302XXX
WD-WMAJ9127XXXX
WDC WD80 0JD-00HKA0 SCSI Disk Device

My computer’s hardware serial number:
5a902af52d637fcc4aa48425784d2a73
45fde343d3acd51d8ba4bc305a24fe3f
e1a5194ed9352fa50e0d914777fceab

Nice, isn’t it?

Download

Download HWSNGen unit
Download MD5 unit
Download MagWMI


Usage
I’ll give 10 beers to guy who create easier thing to use.
uses HWSNGen;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=GenerateHWSN;
end;