Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-08

Getting disk label and serial numbers

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rolf Grunsky

I am currently trying to write a catalog program for my archive CD-ROM's and I can not find a working method of a) getting the volume label and b) getting the serial number.

I am looking for a method that will work with both Win32 and OS/2. FindFirst with the volumeid attribute does not work with Win32 (and I know does not work with OS/2). I was a little surprised that there are no functions to read this information in the sysutils unit since it seems to be a common enough function. But I'm an old DOS programmer and maybe I'm missing something. I could use the DOS functions (Int21) but I really do want a native solution. In any case Win32 supports longer volume label name on CD-ROM's than either DOS or OS/2 does. Any pointers in the right direction would be appreciated.

And for a related project, where can I find a Pascal implementation of the MD5 secure hash?

Many thanks

Rolf Grunsky

RGrunskyAtSympaticoDotCa Truth in her dress finds facts too tight. In fiction she moves with ease. Rabinranath Tagore
Unknown author
to Rolf Grunsky
Rolf Grunsky wrote 16 lines
I am currently trying to write a catalog program for my archive CD-ROM's and I can not find a working method of a) getting the volume label and b) getting the serial number. I am looking for a method that will work with both Win32 and OS/2. FindFirst with the volumeid attribute does not work with Win32 (and I know does not work with OS/2). I was a little surprised that there are no functions to read this information in the sysutils unit since it seems to be a common enough function. But I'm an old DOS programmer and maybe I'm missing something. I could use the DOS functions (Int21) but I really do want a native solution. In any case Win32 supports longer volume label name on CD-ROM's than either DOS or OS/2 does. Any pointers in the right direction would be appreciated. And for a related project, where can I find a Pascal implementation of the MD5 secure hash?
Check out the packages. Directory base/md5 contains a tested md5 hash;

Michael.

www
to Rolf Grunsky: I am currently trying to write a catalog program for my archive CD-ROM's and I can not…

RG> I am currently trying to write a catalog program for my archive CD-ROM's RG> and I can not find a working method of a) getting the volume label and RG> b) getting the serial number.

this function get unique CDId
probable work with win32 :)

uses Windows,MMSystem;
Function GetCDId(DeviceName: PChar; Buf: PChar; BufSize:Integer):Boolean;
 Var OpenParm: TMCI_Open_Parms;
     InfoParm: TMCI_Info_Parms;
     FError : Integer;
     FDeviceID: Word;
Begin
   GetCDId:=false;
   FillChar(OpenParm, SizeOf(TMCI_Open_Parms), 0);
   OpenParm.dwCallback := 0;
   Integer(OpenParm.lpstrDeviceType) := MCI_DEVTYPE_CD_AUDIO {'CDAudio'};
   OpenParm.lpstrElementName := DeviceName;
   FError := mciSendCommand (  0,
                               mci_Open, MCI_OPEN_ELEMENT or
                               MCI_OPEN_TYPE_ID or mci_Wait or
                               mci_Open_Type or
                               mci_Open_Shareable,
                               Longint(@OpenParm));
   FDeviceID := OpenParm.wDeviceID;
   if FError = 0 then begin
    FillChar(InfoParm, sizeof(TMCI_Info_Parms), 0);
    InfoParm.lpstrReturn := Buf;
    InfoParm.dwRetSize:=BufSize;
    FError:=mciSendCommand(FDeviceId, MCI_INFO, MCI_INFO_MEDIA_IDENTITY, longint(@InfoParm));
    GetCDId:=FError=0;
   end;
   MCISendCommand(FDeviceID, MCI_CLOSE, 0, 0);
end;
С уважением, www
Unknown author
to Rolf Grunsky: I am currently trying to write a catalog program for my archive CD-ROM's and I can not…

Date sent: Thu, 08 Aug 2002 14:44:19 -0400
From: Rolf Grunsky
To: Free Pascal List
Subject: [fpc-pascal]Getting disk label and serial numbers Send reply to:

I am currently trying to write a catalog program for my archive CD-ROM's and I can not find a working method of a) getting the volume label and b) getting the serial number. I am looking for a method that will work with both Win32 and OS/2.

.
.

I suspect the only method working on both platforms is using IFDEF directive here (or a function with IFDEF directive inside ;-) ). I can't help with Win32, but for OS/2 it might look like:

***
program QueryFS;
uses
 DosCalls;
var
 I: TFSInfo;
 RC: longint;
 N: byte;
 C: char;
 S: string;
begin
 if ParamCount = 0 then
 begin
  WriteLn ('Disk letter expected!');
  Halt (1);
 end;
 S := ParamStr (1);
 C := Upcase (S [1]);
 N := Ord (C) - 64;
 WriteLn ('Working on ', C, ':');
 RC := DosQueryFSInfo (N, 2, I, SizeOf (I));
 if RC  0 then
  WriteLn ('Error ', RC, ' while obtaining volume information.') else
 begin
  WriteLn ('Volume label is "', I.VolumeLabel, '"');
  WriteLn ('Serial number is ', cardinal (I.Label_Date) shl 16 +
I.Label_Time);
 end;
end.
***

You'll probably want to convert the serial number to hexadecimal (it's shown as decimal here).

And for a related project, where can I find a Pascal implementation of the MD5 secure hash?

There's a unit md5 in FPC packages (/packages/base/md5 in CVS). It's a fairly new addition there, so it wasn't distributed with any release yet (it should appear in snapshots).

Tomas

Unknown author

From: Self
To:
Subject: Re: [fpc-pascal]Getting disk label and serial numbers Send reply to:
Date sent: Thu, 8 Aug 2002 22:08:49 +0200

WriteLn ('Serial number is ', cardinal (I.Label_Date) shl 16 + I.Label_Time);

Sorry, this is the other way round:
cardinal (I.Label_Time) shl 16 + I.Label_Date

Tomas

Yet Another Geek
program cdname;

{ Here is a simple Windows 98 example that
prints the Drive Letter, Volume name,
and SerialNumber of your CDROM drives
to StdOut ...
You may need to $IFDEF this to use WideChars on
NT/2000/XP !
}

uses windows;
var
 DrvStr : string[4];
 pszVolName : array[0..11] of char;
 pdwSerNum, dwMaxFNLen, dwFSysFlags : DWORD;
 pszFSysName : array[0..127] of char;
 DrvChr : Char;

begin

  DrvStr := '?:\' + #0; { the '?' is just a

placeholder }

  for DrvChr := 'C' to 'Z' do begin
    DrvStr[1] := DrvChr;
    if ( GetDriveType(@DrvStr[1] ) = DRIVE_CDROM )
    and  GetVolumeInformation(
          @DrvStr[1], @pszVolName[0],

SizeOf(pszVolName),
@pdwSerNum, dwMaxFNLen,
dwFSysFlags,
@pszFSysName, SizeOf(pszFSysName)
)
then

    WriteLn(DrvChr, #9, pszVolName, #9,  pdwSerNum);
  end;
  WriteLn('Press Return');
  { pause before closing the DOS window ...}
  ReadLn;
end.

__________________________________________________ Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com