?
Solved

Is CD In Drive?

Posted on 2003-03-02
41
Medium Priority
?
237 Views
Last Modified: 2010-04-04
I have Delphi 7 and Windows XP. I searched around of the question and basicy found nothing that worked. The stuff listed here: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20273665.html does not want to work on Windows XP. It doesn't detect anything, wheather I insert or eject the disk. I have 2 CD-Roms, maybe that's why, but I just have no idea on how to get this thing to work. The stuff I found @ torry requires stuff delphi 7 does not have Desginf, etc.

Please help
0
Comment
Question by:the_modder
[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
  • 21
  • 10
  • 8
  • +1
41 Comments
 
LVL 1

Expert Comment

by:TAZI
ID: 8056133
Hi

I tried this in Windows 2000 ... Delphi 5

function DiskInDrive(Drive: Char): Boolean;
var
  ErrorMode: Word;
begin
  { make it upper case }
  if Drive in ['a'..'z'] then Dec(Drive, $20);
  { make sure it's a letter }
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  { turn off critical errors }
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    { drive 1 = a, 2 = b, 3 = c, etc. }
    if DiskSize(Ord(Drive) - $40) = -1 then
      Result := False
    else
      Result := True;
  finally
    { Restore old error mode }
    SetErrorMode(ErrorMode);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if DiskInDrive('D') = False then
     ShowMessage('Drive not ready')
  else
     ShowMessage('Drive Ready');
 end;

Hope this information is useful

Regards
TAZI
0
 
LVL 1

Expert Comment

by:TAZI
ID: 8056168
Hi

Also, you can detect the number of CD Rom Drives on the machine and the drive letter associated with that drive.

Herewith, the code that can detect that information.

function GetFirstCDROMDrive: char;
var
  drivemap, mask: DWORD;
  i: integer;
  root: string;
begin
  Result := #0;
  root := 'A:\';
  drivemap := GetLogicalDrives;
  mask := 1;
  for i := 1 to 32 do
  begin
    if (mask and drivemap) <> 0 then
      if GetDriveType(PChar(root)) = DRIVE_CDROM then
      begin
        Result := root[1];
        Break;
      end;
    mask := mask shl 1;
    Inc(root[1]);
  end;
end;


{********************************}

function GetNumberOfCDDrives: Byte;
var
  drivemap, mask: DWORD;
  i: integer;
  root: string;
begin
  Result := 0;
  root := 'A:\';
  drivemap := GetLogicalDrives;
  mask := 1;
  for i := 1 to 32 do
  begin
    if (mask and drivemap) <> 0 then
      if GetDriveType(PChar(root)) = DRIVE_CDROM then
      begin
        Inc(Result);
      end;
    mask := mask shl 1;
    Inc(root[1]);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //** NO OF CD ROM DRIVES ON MACHINE **/
  Label1.Caption := IntToStr(GetNumberOfCDDrives);
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
  //** DRIVE LETTER **/
  ShowMessage(GetFirstCDROMDrive);
end;
end.

Regards
TAZI
0
 
LVL 1

Author Comment

by:the_modder
ID: 8061340
Read this link: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20273665.html . I want something that uses WMDEVICECHANGE, so I can detect when the disk is being READ! That's what I want to do. For some reason I can't get the code to work. I put it in a form, and I play around with both of my cd-drives and no messeges come up!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:the_modder
ID: 8062055
Like I can't get this: http://www.torry.net/vcl/filedrv/cd/cdevents.zip to work in delphi 7 and under XP. I can't even load it into a form without getting errors like DsgnIntF when I include CDEvents in the uses of Form1.

Can anyone help? Basicly what I want to do is contained in the CDEvents file. I want to get it to work.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8063029
Hi,
You can download a programm DISKSN.exe from which is developed by Delphi 6.0 on Windows XP:
http://eo-soft.addr.com/
0
 
LVL 1

Author Comment

by:the_modder
ID: 8068422
No, I do not need the serial number of the disk. I need to find out when the disk is being READ! I don't need to know when the disk is recognized by explorer, cuz I already know how to do that =)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8075600
The question is: "Is CD In Drive?"
When the drive do not contains CD or the tray is opened you will see serial number = 0,
When the drive contains CD and the tray is closed you will see the CD's serial number.
If you need to find out when the disk is being READ, just ask question: "is the disk being READ?"
0
 
LVL 1

Author Comment

by:the_modder
ID: 8076237
Ok, fine I messed up on the title. So?
0
 
LVL 1

Author Comment

by:the_modder
ID: 8086236
ANYONE??
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8088656
Try to hook this:

Private
    { Private declarations }
    Procedure WMDeviceChange(Var Msg: TMessage); message WM_DEVICECHANGE;


Procedure TForm1.WMDeviceChange(Var Msg: TMessage);
Const
  CD_IN = $8000;
  CD_OUT = $8004;
Begin
  Inherited;
  Case Msg.wParam Of
    CD_IN   : ShowMessage('CD in');
    CD_OUT  : ShowMessage('CD out')
  End
End;
0
 
LVL 1

Author Comment

by:the_modder
ID: 8273785
Sorry ginsonic =(

The code doesn't do anything. I just get a blank form and when I eject or inject either of my 2 cd-rom drives nothing comes up =(

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    Procedure WMDeviceChange(Var Msg: TMessage); message WM_DEVICECHANGE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Procedure TForm1.WMDeviceChange(Var Msg: TMessage);
Const
 CD_IN = $8000;
 CD_OUT = $8004;
Begin
 Inherited;
 Case Msg.wParam Of
   CD_IN   : ShowMessage('CD in');
   CD_OUT  : ShowMessage('CD out')
 End
End;

end.
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 200 total points
ID: 8282066
Hi,
try the last version of DISKSN.exe from:
http://eo-soft.addr.com/
it is the best I can develope for now !!!
0
 
LVL 1

Author Comment

by:the_modder
ID: 8288158
Yeh, DISKSN works GREAT! Now if you can give me the source I'll give you 50 points =)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8290149
I just uploaded DISKSN.zip with Delphi 6.0 code of DISKSN.exe
I am glad to help you,
emil
0
 
LVL 1

Author Comment

by:the_modder
ID: 8295723
So Where's the code?
0
 
LVL 1

Author Comment

by:the_modder
ID: 8296213
Great!

That's exactly what I needed!

Thanks for the code.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8297607
I'm interested to take a look to codes, but I think that aren't available on net anymore.

I offer 200 points for these lines. Can I?
0
 
LVL 1

Author Comment

by:the_modder
ID: 8476510
Ok.

I have finnaly had time to play around with the code.

Just a quick question: how do I detect letter of the disk that was inserted.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8477003
Where can I get de zip file with the source? I offer points fot this.
0
 
LVL 1

Author Comment

by:the_modder
ID: 8480372
I have the file on my hard drive. But I do not understand how to detect which(what) disk was inserted.

I will go home and upload the file to my server.
0
 
LVL 1

Author Comment

by:the_modder
ID: 8483857
Here ginsonic:

http://jimhasskillz.servequake.com/~dburban/DISKSN.zip

So, do you know how to display the letter of the disk that was ejected/injected?
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8485138
the_modder, I added 200 points in 'Points for the_modder'.  About your problem I will take a look to the code.
0
 
LVL 1

Author Comment

by:the_modder
ID: 8489282
Great! Thanks!

I'll also give you points =)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8497361
 Excuse me,

  I did stop to read the comments about this question after I got the points from the_modder.
If anybody is interested of this code and offers so fantastic amount of 200 points. I love the points :-)
  I will publish the code again. I think it will be a great deal for me, WOW !!!!

:-)

emil
0
 
LVL 1

Author Comment

by:the_modder
ID: 8497383
I got the points from ginsonic already =)

Do you have an idea of how to detect the name of the disk that was inserted?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8498009
 I really have not an idea of how to detect the name of the disk that was inserted or ejected, but I do not stop to search about.
  I believe there is some unpublished (or published but unknown for me)  Microsoft's function that provides this information. It just wait to be found !!!!
  Best regards,
emil
0
 
LVL 1

Author Comment

by:the_modder
ID: 8501320
I was kind of thinking of making a buffer for the listview. If something is not the same then it will report the thing that is not the same.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8502855
the_modder please let a comment here to paq the question and to get your points:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20611891.html
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8502857
esoftbg, I will put a question with 200 points for you, too. Thank for sharing :)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8503735
I will share the last version of DISKSN's code after 10-12 hours. Please wait...
emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 8505767
please visit:
http://eo-soft.150m.com/
for the last version of disksn's Delphi 7 source code

emil
0
 
LVL 1

Author Comment

by:the_modder
ID: 8513845
Hey, ginsonic: I just notice you said you'd give me 200 points =)

Anyway I don't really care =)
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8513984
My pleasure :)
0
 
LVL 1

Author Comment

by:the_modder
ID: 8522001
Here's how I got my computer to tell me if E is ejected or inserted:

procedure TFormDevices.WMDEVICECHANGE(var msg:tmessage);
const
  DBT_DEVICEARRIVAL = $8000;
  DBT_DEVICEMOVECOMPLETE = $8004;
var
  S:      string;
  temp : string;
  temp1 : string;
begin
  inherited;
  S := '';
  //listview1.Items.Item[b].SubItems[3]
  temp := lv.Items.item[1].SubItems[2];
  edit1.Text := temp;
  try
    case msg.WParam of
      DBT_DEVICEARRIVAL:      S := 'CD disk was Inserted';
      DBT_DEVICEMOVECOMPLETE: S := 'CD tray was Ejected';
    end;
  finally
  Check_Devices(false);
  temp1 := lv.Items.item[1].SubItems[2];
  if temp1 = temp then
  else
  if temp = '00000000' then
  showmessage('F Inserted')
  else
  showmessage('F Ejected');

    EditCD.Text := S;
//    ShowMessage(S);
  end;
end;
0
 
LVL 1

Author Comment

by:the_modder
ID: 8524817
Ok. I was playing around with the code yesturday and I almost figured out how to get the right disk, and whether it is ejected or inserted =)
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8529281
May we see the final solution :)
0
 
LVL 1

Author Comment

by:the_modder
ID: 8529629
Today I worked on it some more.

It can now tell which drive the cd was INJECTED into.

I am still working on the ejection part =)

I'll post the updated code when it's finished, but I did remove the create listview (cuz i could not acess some features in it).
0
 
LVL 1

Author Comment

by:the_modder
ID: 8529660
Ok. I FINISHED IT!!!!!

Here's the link: http://jimhasskillz.servequake.com/~dburban/DISKSN80.zip

BTW: I tried to minimize the ammount of strings I use, so that's why I have so much code =) And yes, there are some varibale I made that do not need to be there =|

Have fun!

Hope to see some improvements.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8531716
thanks for sharing :)
0
 
LVL 1

Author Comment

by:the_modder
ID: 8533858
No problem.

Does it work on your computer??

You can clean up the code a bit if you like and send it to me =)

Hope you like what I did to it =)

This week I will intergrate it into the app that I needed it to be in =)))
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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