Download MetaTrader 5

HOW to use GetDiskSerial.dll in MQL5?

To add comments, please log in or register
Track all payments in your profile. It is easy!
Ma Yuliang
255
Ma Yuliang 2015.10.19 14:27 

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 ?
Ma Yuliang
255
Ma Yuliang 2015.10.19 14:54  

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 ?

Laszlo Tormasi
2723
Laszlo Tormasi 2015.10.19 16:42  
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.   

Osama Shaban
1448
Osama Shaban 2015.10.19 21:41  

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:
Carl Schreiber
6588
Carl Schreiber 2015.10.21 09:28  
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!!

Anton Nel
37045
Anton Nel 2015.10.21 11:41  

Try this - see files attached:

 

Carl Schreiber
6588
Carl Schreiber 2015.10.21 14:17  

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.

Anton Nel
37045
Anton Nel 2015.10.21 15:24  
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:


Carl Schreiber
6588
Carl Schreiber 2015.10.24 09:51  
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:


Anton Nel
37045
Anton Nel 2015.10.25 07:37  

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. 

 


 


Carl Schreiber
6588
Carl Schreiber 2015.10.25 11:14  

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.

12
To add comments, please log in or register