Page 1 of 2

Harddisk manufacturing information library

Posted: Sun Jun 15, 2003 6:59 am
by Revolver
I just finished version 1.0 of my DiskInfo library. This dll will give you details about hard disk drives attached to the IDE controllers of your pc. You can get it here:

http://diskinfo.nakatome.org/diskinfo.rar
or http://diskinfo.nakatome.org/diskinfo.zip
Don't forget to read readme.txt!

Here is an example (also provided in the archive) of how to use this library

Code: Select all

Structure DISK_INFO
  ModelNumber.b[64]
  SerialNumber.b[64]
  ControllerVersion.b[64]
  ControllerID.b
  BufferSize.l
  Type.b
  Sectors.l
  DiskSize1.l ; *COUGH* could use 64 bit integer support here !!
  DiskSize2.l
EndStructure

If OpenLibrary(0,"diskinfo.dll") = 0
  Debug "LIBRARY OPEN FAILED"
EndIf

; First you have to know how many hard disks are attached
; to the system. This will always be between 1 and 4.
DiskCount = CallFunction(0,"GetDiskCount")
Debug "Detected "+ Str(DiskCount) +" hard disk(s)"
Debug ""

; You can retrieve the data all at once by declaring the appropriate
; structure, and calling the GetDiskInfo() function. You can then
; get each piece of data out of the structure manually.

DiskInfo.DISK_INFO
ModelNumber.s       = Space(64)
SerialNumber.s      = Space(64)
ControllerVersion.s = Space(64)

For DiskID = 1 To DiskCount
  Debug "Disk - "+ Str(DiskID)
  Result = CallFunction(0,"GetDiskInfo",DiskID,@DiskInfo);
  
  CopyMemory(@DiskInfo\ModelNumber,      @ModelNumber,      64)
  CopyMemory(@DiskInfo\SerialNumber,     @SerialNumber,     64)
  CopyMemory(@DiskInfo\ControllerVersion,@ControllerVersion,64)
  
  Debug "  Model Number: "+ ModelNumber
  Debug "  Serial Number: "+ SerialNumber
  Debug "  Controller Version: "+ ControllerVersion
  
  Select DiskInfo\ControllerID
    Case 1: Debug "  This disk is on the Primary IDE Controller (Master)"
    Case 2: Debug "  This disk is on the Secondary IDE Controller (Slave)"
    Case 3: Debug "  This disk is on the Tertiary IDE Controller (Master)"
    Case 4: Debug "  This disk is on the Quaternary IDE Controller (Slave)"
  EndSelect
  
  Select DiskInfo\Type
    Case 0: Debug "  Type: Unknown"
    Case 1: Debug "  Type: Fixed"
    Case 2: Debug "  Type: Removable"
  EndSelect
  
  Debug "  Buffer Size: "+ Str(DiskInfo\BufferSize) +" bytes"
  Debug "  Disk Size: "+ StrF(DiskInfo\Sectors * 512,0) +" bytes" ; This little hack will work For drives up To 2TB large.
  ;Debug "  Disk Size: "+ Str(DiskInfo\DiskSize) +" bytes"         ; Hopefully by the time those are here, PB will have 64-bit
                                                                   ; integer support, so we don't have to do that hack!
  Debug ""
Next

; Or, you can get each piece of data one at a time. Useful
; if you only want to know certain things about the disk
DiskSize.l
DiskSerial.s = Space(64)
If CallFunction(0,"GetDiskSectors",1,@DiskSize)
  Debug "Disk 1 size: "+ StrF(DiskSize * 512,0) +" bytes"
EndIf
; If you only have 1 hard disk, this will show nothing
If CallFunction(0,"GetDiskSerial",2,@DiskSerial)
  Debug "Disk 2 serial: "+ DiskSerial
EndIf

CloseLibrary(0)

End
This has not been thoroughly tested, only on Windows XP SP1, and Windows 98. If you get it to work please post here with your operating system and hard disk specs!

Enjoy !

(Don't worry Rings, this isn't the code you gave me. I was finally able to get that C++ code transformed into a DLL properly :)

Posted: Sun Jun 15, 2003 7:05 am
by Revolver
Also, don't be fooled. This is not the same thing as you can get with the API command GetVolumeInformation. That command only works for logical drive partitions. This will return the actual serial number for the hard disk itself, as issued by the company that manufactured it. Volume serial numbers will be changed any time the disk is reformatted or repartitioned. The serial number issued by this library will never change, unless they get a new hard drive :)

Posted: Sun Jun 15, 2003 4:50 pm
by Kale
Very nice work Revolver!

This should be very handy to those wishing to protect software using a hardware fingerprint, etc...

Posted: Mon Jun 16, 2003 10:15 am
by Rings
Yes, i have written code for that in plain purebasic weeks ago.
[NUM] and Revolver owns it.Some day i will release it to everyone :)

Posted: Mon Jun 16, 2003 11:52 am
by RJP Computing
@Rings,
That would be great. Can't wait.

@Revolver
Looks nice.

Works on WinXP SP1 & IBM HD
Works on Win2K SP3 & WD HD

Thanks

Posted: Mon Jun 16, 2003 6:51 pm
by ricardo
Hi Revolver,

Very nice job!!

How can i know on which of the hds of the array are my software installed?
I mean, i want to know only the serial of the hd where the software is.

Posted: Mon Jun 16, 2003 7:26 pm
by Num3
Works fine on windows 2k and NT4 :lol:

Posted: Mon Jun 16, 2003 10:00 pm
by PB
> i have written code for that in plain purebasic weeks ago.

Please release it soon. :) DLLs are good, but I don't really like them.

Posted: Tue Jun 17, 2003 12:42 am
by Revolver
ricardo: hmm, you could somehow find out which ide controller the virtual drive is using that your software is on, then cycle through the drives given by the dll until you find one that's ControllerID matches. I don't know how to get the ide controller id for a virtual drive though..

Posted: Tue Jun 17, 2003 1:00 am
by Inner
Does it work on Cdrom drivers too ?

Posted: Tue Jun 17, 2003 10:33 am
by Rings
PB wrote:> i have written code for that in plain purebasic weeks ago.

Please release it soon. :) DLLs are good, but I don't really like them.
done.
viewtopic.php?p=28162#28162

Posted: Tue Jun 17, 2003 11:43 am
by PB
Thanks Rings! :D

Posted: Tue Jun 17, 2003 7:11 pm
by Revolver
Inner wrote:Does it work on Cdrom drivers too ?
nope

Posted: Fri Oct 03, 2003 4:27 pm
by TerryHough
@Revolver

Your code works perfectly on my Win98SE system for the first hard
drive. The remaining hard drives attempt to display but the information
displayed is either blank, or completely inaccurate.

I just downloaded your zip file today so I should have the latest version
you have made available.

Do you have any suggestions as to why other drives misreport? In my
case I have three hard drives located on Primary (Master),
Primary (Slave), and Secondary (Master).

Thanks,
Terry

Posted: Sun Nov 30, 2003 12:37 pm
by Jordi
Does anyone know where I can download the Revolver DISKINFO dll?

I need do a non professional protection system for Windows XP based system getting the HDD SN but it's not useful using Rings code in a no administration user, you need administration permissions to get the SN right. Is there any way to get the SN with this method?

Thks in advance!