HOW to use GetDiskSerial.dll in MQL5?

 

I am trying to use GetDiskSerial.dll in mql4 to get HDD serail num.



{*******************************************************}
{                                                       }
{       Borland Delphi Interface Unit                   }
{                                                       }
{       Copyright (c) 2002-2011, Devlib,Inc.            }
{                                                       }
{       http://www.devlib.net                           }
{                                                       }
{*******************************************************}

unit HDiskInfo;

interface

type

  DiskInfo = record
    SerialNumber: array[0..19] of AnsiChar;
    ModelNumber: array[0..39] of AnsiChar;
    FirmwareRev: array[0..8] of AnsiChar;
    InterfaceType: array[0..9] of AnsiChar;
    MediaType: array[0..39] of AnsiChar;
    BufferSize: Longword;
    Cylinders: Longword;
    Heads: Longword;
    Sectors: Longword;
    SectorsPerTrack: Longword;
    BytesPerSector: Longword;
  end;
  PDiskInfo = ^DiskInfo;

  procedure SetLicenseKey(RegCode: PAnsiChar); stdcall; external 'GetDiskSerial.dll';
  function GetDllVer: PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetDriveCount: Byte; stdcall; external 'GetDiskSerial.dll';
  function GetDriveLetter(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetDriveSize(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetDriveInfo(DriveIndex: Byte; var DiskInfo: DiskInfo): LongBool; stdcall; external 'GetDiskSerial.dll';
  function GetSerialNumber(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetModelNumber(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetFirmwareRev(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetInterfaceType(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';
  function GetMediaType(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';    
  function GetBufferSize(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetCylinders(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetHeads(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetSectors(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetSectorsPerTrack(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetBytesPerSector(DriveIndex: Byte): Longword; stdcall; external 'GetDiskSerial.dll';
  function GetDiskVolumeNumber(DriveLetter: PAnsiChar): PAnsiChar; stdcall; external 'GetDiskSerial.dll';

implementation

end.




my code in mt4 like this

#import "GetDiskSerial.dll"
char GetSerialNumber(void);
#import

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
  
   MessageBox(CharToString(GetDriveSize()));

  }

but i got ritical error when I run this script

and error in the log like this

2015.10.19 20:18:58.133    test USDJPY,H1: stack damaged, check DLL function call in 'test.mq4' (30,28)

I know it is the parameter I passed is not good, but I do not know how to make it correct.

anyone know the right way to code this ?
 

I google the parameter type Byte is 0-255       in  mql4 we use uchar.so I rewrite my code like this


#import "GetDiskSerial.dll"
string GetSerialNumber(uchar);

#import

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   MessageBox(GetSerialNumber(0));
  }

It worked no error come but the result is unreadable like this "?X??????"

what is wrong ?

 
Ma Yuliang:

I google the parameter type Byte is 0-255       in  mql4 we use uchar.so I rewrite my code like this


It worked no error come but the result is unreadable like this "?X??????"

what is wrong ?

You can't use the "GetSerialNumber" function because it returns a pointer to a char and MQL4 is not compatible with this method.

Import "GetDriveInfo" instead.   

 

I got this script in mql4 ex4 format only. It could help you if you only want to see the HDD serial or send it to your clients for licensing purpose.

I did a lot of searching and coding to include it in the code to verify the serial number to let the EA to work or block it, but didn't succeed yet :( 

Files:
RobotCode.ex4  6 kb
 
Osama Shaban:

I got this script in mql4 ex4 format only. It could help you if you only want to see the HDD serial or send it to your clients for licensing purpose.

I did a lot of searching and coding to include it in the code to verify the serial number to let the EA to work or block it, but didn't succeed yet :( 

You can't get it as you need Admin.-rights to get this info!

It's a Windows problem. After Win XP they decided that this serial number has to protected!!

 

Try this - see files attached:

 

 

Well I do get something: 000092F2D1ED (12 char) but this is not the "Hard Drive Uniqe ID" which should be (in my case): S1SXNSAF908244V (15 char).

Everything else works perfectly.

 
calli:

Well I do get something: 000092F2D1ED (12 char) but this is not the "Hard Drive Uniqe ID" which should be (in my case): S1SXNSAF908244V (15 char).

Everything else works perfectly.

I looked at "Volume Serial Number" -- see screenshot below:


 
Anton Nel:

I looked at "Volume Serial Number" -- see screenshot below:


What you show seem to be Windows' partition ID not the (hardware's) volume serial number.

Starting the Hardware ID extractor as user I  get:


Now after this program has been started with admin-rights i get:


 

Thank you calli for showing us the difference between Partition ID and Hard Drive Unique ID.

I have managed to write the code to get the Hard Drive Unique ID information from the hard drive. 

 


 


 

This is what your EA printed:

2015.10.25 10:40:29.410 Sampe02_GetDiskSerialNumber_EA EURUSD,M1: initialized
2015.10.25 10:40:19.095 Sampe02_GetDiskSerialNumber_EA EURUSD,M1: Hard Drive Unique ID: 31535853534e4641303932383434205620202020
2015.10.25 10:40:17.000 Sampe02_GetDiskSerialNumber_EA EURUSD,M1: Partition ID: 92F2-D1ED
2015.10.25 10:40:14.667 Sampe02_GetDiskSerialNumber_EA EURUSD,M1: TestFox: The quick brown fox jumps over the lazy dog.
2015.10.25 10:40:02.672 Sampe02_GetDiskSerialNumber_EA EURUSD,M1: GetDiskSerialNumber.dll Checksum Add(1 + 25) = 26
2015.10.25 10:39:43.305 Expert Sampe02_GetDiskSerialNumber_EA EURUSD,M1: loaded successfully

I have Win 7, 64 and a SSD-Hd! I read somewhere: Until XP Windows has allowed this access!

In the DOS-Box I have - as user (and as admin):

I have posted a question about this in a German Windows-server forum. I'll let you know, we'll see.
C:\Windows\system32>dir/p/w
 Volume in drive C has no label.
 Volume Serial Number is 92F2-D1ED

I have posted a question about this in a German Windows-server forum. I'll let you know, we'll see.

Let me add that Samsung's Magician (it comes with the hd and has to be started by the Admin.) shows this as SerialNo.: S1SXNSAF098244V so this number I should get.

Reason: