?
Solved

How do I get Hard-disk serialnumber?

Posted on 1998-03-03
10
Medium Priority
?
501 Views
Last Modified: 2010-04-06
I want to get the users harddisk-serialnumber, from within my application. is this possible to do in an easy way? How do I do it?

I use Delphi Developer 2.0
/Erik N
0
Comment
Question by:Erik N
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 

Author Comment

by:Erik N
ID: 1360026
Edited text of question
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1360027
This is from The Help file called: Borland Technical Informations.
Hope it helps.

Title      : Getting and setting a disks serial numberProduct      : PascalVersion      : AllOS      : DOSDate      : March 13, 1996Number      : 1759

The following program shows how to read and write the serial
number on a disk drive. It uses interrupt $21 function $69
and reads the information back and forth into a record with
the following declaration:

  TSerPacket = record
    Info:Word;
    SerNo: Longint;
    Vol: Array[1..11] of char;
    FileType: Array[1..8] of char;
  end;

The first word of the above record should always contain
zero, the second contains the serial number, the third
the volume label and the fourth the FileType, which is usually

either FAT 16 or FAT 12.

When setting a new serial number, the programs first reads the
current information, and then sets the new serial number
and writes it to disk.

The code shown below provides the user with three functions:

  GetSerialInfo: Get the current serial number
  SetSerialInfo: Set a new serial number
  DisplaySerialInfo: Display the information in the current
                     variable of type TPacket.

Notice that DisplaySerialInfo does not write information

to a disk drive, but only displays that information to
the user via the screen. All of these routines depend
on a global variable of type TSerPacket, which is called
SPacket. It makes no sense to call DisplaySerialInfo
before calling GetSerialInfo.

The drive specification is passed as a number, where
the default drive is zero, drive A is one, drive
B is two, etc.


program SetDiskSer;

{$A+,B-,D+,E+,F-,G+,I+,L+,N-,O-,P-,Q-,R-,S-,T-,V+,X+,Y+}
{$M 16384,0,655360}

type
  TSerPacket = record
    Info:Word;        { Info level always zero }
    SerNo: Longint;   { Disk }
    Vol: Array[1..11] of char;
    FileType: Array[1..8] of char;
  end;

var
  SPacket: TSerPacket;

function GetSerialInfo(Drive: Byte): Byte; assembler;
asm
  mov ah, 69h
  mov al, 0  { This is where you 1 set serial, 0 to get serial
               number }
  mov bl, 1  { drive number 0 = default, 1 = A, 2 = B , 3 = C }
  mov dx, offset [SPacket]

  int 21h
end;


function SetSerialInfo(Drive: Byte; SerNo: LongInt): Boolean;
var
  S: String;
begin
  GetSerialInfo(Drive);
  SPacket.SerNo := SerNo;
  asm
    mov ah, 69h
    mov al, 1  { This is where you 1 set serial, 0 to get serial
                 number }
    mov bl, Drive  { drive number 0 = default, 1 = A, 2 = B ,
                     3 = C }
    mov dx, offset [SPacket]
    int 21h
  end;
end;

procedure DisplaySerialInfo;
var
  S: String;

begin
  WriteLn('Info level: ', SPacket.Info);
  WriteLn('Serial Num: ', SPacket.SerNo);
  FillChar(S, SizeOf(S), #0);
  Move(SPacket.Vol[1], S[1], 11);
  S[0] := #11;
  WriteLn('Vol: ', S);
  FillChar(S, SizeOf(S), #0);
  Move(Spacket.FileType,S[1], 8);
  S[0] := #8;
  WriteLn('Type: ', S);
end;

begin
  SetSerialInfo(1, 12);  { One means Drive A, 16 is the serial
                           number }
  GetSerialInfo(1);
  DisplaySerialInfo;
  ReadLn;
end.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360028
Hi

I don't want to tread on ronit's toes, but the "GetVolumeInformation" Windows API call is a lot easier...   ;-)

Cheers,
JB
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:ronit051397
ID: 1360029
Actally you are right JB.
Erik, an example of using GetVolumeInformation can be found in:
http://www.chami.com/tips/delphi/122596D.html
0
 
LVL 5

Expert Comment

by:inter
ID: 1360030
Here is the pascal prototype and little info if you bored from Win32 helps C style:

function GetVolumeInformation(
  lpRootPathName: PChar; // address of root directory of the file system
  lpVolumeNameBuffer: PChar;    // address of name of the volume
  nVolumeNameSize: DWORD;       // length of lpVolumeNameBuffer
  lpVolumeSerialNumber: PDWORD;         // address of volume serial number
  var lpMaximumComponentLength,         // address of system's maximum filename length
  lpFileSystemFlags: DWORD;             // address of file system flags
  lpFileSystemNameBuffer: PChar;        // address of name of file system
  nFileSystemNameSize: DWORD): BOOL;    // length of lpFileSystemNameBuffer

Bye,
Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360031
Hi Erik N,
Hi everybody,

This should work : very easy, very simple, and with example :

procedure TForm1.Button1Click(Sender: TObject);
var
  SerialNum : pdword;
  a, b : dword;
  Buffer  : array [0..255] of char;
begin
  if GetVolumeInformation('c:\', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then
    Label1.Caption := IntToStr(SerialNum^);
end;

Regards, Zif.

0
 
LVL 4

Expert Comment

by:itamar
ID: 1360032
Hi Erik,

if you really want to make it in a easy way, don't do it - use a ready component !

http://www.torry.webnorth.com/vcl/filedrv/drives10.zip

or (the one I prefer)

http://sunsite.icm.edu.pl/delphi/ftp/d10free/volin101.zip

And if your goal is distribution protection I can sugest you a complete component that deals with everything you can imagine in this area ,like activation-key generation, time expiration, etc...

IHTH,
Itamar

http://www.torry.webnorth.com/vcl/filedrv/diskcaps.zip
(By Radoslaw Przybyl.
                                This simple component
                                encapsulates two API
                                functions:
                                GetVolumeInformation
                                and GetDriveType. It
                                allows to check:

                                    Drive Volume Label
                                    Drive Serial Number
                                    Drive file system
                                    type
                                    Length of directory
                                    component
                                    Drive System Flags )

0
 
LVL 4

Accepted Solution

by:
itamar earned 240 total points
ID: 1360033
Correction:
>>>>>>>>
Hi Erik,

     if you really want to make it in a easy way, don't do it - use a ready
     component !

     http://www.torry.webnorth.com/vcl/filedrv/drives10.zip

     or



     http://www.torry.webnorth.com/vcl/filedrv/diskcaps.zip
     (By Radoslaw Przybyl.
                                     This simple component
                                     encapsulates two API
                                     functions:
                                     GetVolumeInformation
                                     and GetDriveType. It
                                     allows to check:

                                         Drive Volume Label
                                         Drive Serial Number
                                         Drive file system
                                         type
                                         Length of directory
                                         component
                                         Drive System Flags )

     or (the one I prefer)

     http://sunsite.icm.edu.pl/delphi/ftp/d10free/volin101.zip

     And if your goal is distribution protection I can sugest you a complete
     component that deals with everything you can imagine in this area ,like
     activation-key generation, time expiration, etc...

     IHTH,
     Itamar

0
 
LVL 4

Expert Comment

by:itamar
ID: 1360034
Hei !

It was supposed to be a comment !!!!!

Sorry !
Itamar
0
 

Author Comment

by:Erik N
ID: 1360035
Thanks to all of you...
I tried Zif's method and it didn't work properly, I don't know why though... (I got "Access violation").

/Erik N
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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