Solved

How to get "disk serial number"

Posted on 1997-06-10
2
319 Views
Last Modified: 2010-04-03
I need compare a decrypted string with the serial number of the disk where it is installed, as a way to avoid people to duplicate the software I deliver to them. I have not heard from a clever method to get access to that serial number string.
I presently achieve it (Delphi 1 Windows 3.11) with a not very clever method, though efficient : I use ShellExecute passing the command "command.com /c dir c:\ >text.tmp", launching the DOS command interpreter, using the DIR command, and redirecting the output into a text file, from which I read the line where the useful information is written. Do you have any clever method avoiding this call to DOS ?
0
Comment
Question by:pousticrousti
2 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1336957
With Win32, this is easy. But with Windows 3.x & Delphi 1, it's worth the 200 pts.
This code is tested and it works fine:

var
  Form1   : TForm1;
  SerialNo: LongInt;

implementation

{$R *.DFM}

type
  TDriveChar = '@'..'Z'; {'@' = current, 'A', 'B', etc.}

  PRealModeRegs = ^TRealModeRegs;
  TRealModeRegs = record
    case Integer of
      0: (
        EDI, ESI, EBP, EXX, EBX, EDX, ECX, EAX: Longint;
        Flags, ES, DS, FS, GS, IP, CS, SP, SS: Word);
      1: (
        DI, DIH, SI, SIH, BP, BPH, XX, XXH: Word;
        case Integer of
          0: (
            BX, BXH, DX, DXH, CX, CXH, AX, AXH: Word);
          1: (
            BL, BH, BLH, BHH, DL, DH, DLH, DHH,
            CL, CH, CLH, CHH, AL, AH, ALH, AHH: Byte));
  end;

function RealModeInt(Int: Byte; var Regs: TRealModeRegs): Boolean;
{ procedure invokes int 31h function 0300h to simulate a real mode }
{ interrupt from protected mode. }
var
  ErrorFlag: Boolean;
begin
  asm
    mov ErrorFlag, 0       { assume success }
    mov ax, 0300h          { function 300h }
    mov bl, Int            { real mode interrupt to execute }
    mov bh, 0              { required }
    mov cx, 0              { stack words to copy, assume zero }
    les di, Regs           { es:di = Regs }
    int 31h                { DPMI int 31h }
    jnc @@End              { carry flag set on error }
  @@Error:
    mov ErrorFlag, 1       { return false on error }
  @@End:
  end;
  Result := not ErrorFlag;
end;

function GetVolSerNo(Drive: TDriveChar): LongInt;
type
  PDiskInfo = ^TDiskInfo;
  TDiskInfo = record
    InfoLevel: Word;
    DiskSerNum: LongInt;
    VolumeLabel: array[0..10] of Byte;
    FileSysType: array[0..7] of Byte;
  end;
var
  L: LongInt;
  P: PDiskInfo;
  R: TRealModeRegs;
begin
  Result := 0;
  L := GlobalDOSAlloc(SizeOf(TDiskInfo));
  if L <> 0 then
  try
    P := Ptr(LoWord(L),0);
    FillChar(P^,sizeof(TDiskInfo),0);
    FillChar(R,sizeof(R),0);
    with R do
    begin
      AX := $6900;
      BL := Ord(Drive)-64;
      BH := 0;
      DS := HiWord(L);
      DX := 0;
    end;
    if RealModeInt($21,R) then
      Result := P^.DiskSerNum
  finally
    GlobalDosFree(LoWord(L));
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SerialNo := GetVolSerNo('C');
  Label1.Caption := Format('%04x-%04x', [HiWord(SerialNo), LoWord(SerialNo)]); { Only to make it look like the "dir" output }
end;

Enjoy!

/// John

0
 

Author Comment

by:pousticrousti
ID: 1336958
Thank you very much for this super fast answer. I trust I can rely on it, and will implement it right now. It's worth 200 points for you !
Olivier de Saint Leger
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question