PDA

View Full Version : Check to see if CD is in Drive?



mdxafx
01-10-2007, 09:22 AM
Hi all, hope the year is going well so far!



I've made a group of discs that have video tutorials on them,
when you insert a disc it is recognised through the setting and
checking of registry keys. The discs option allows the user to
create a short cut link to the cd on the desktop (which copies a small
program to the harddrive and then creates a shortcut to the desktop).

The user double clicks the shortcut it access the cd-rom drives
to see if the disk is in one of the drives set it the Registry!

Problem:-

This all works fine, but i have been trying to add the function that check if there is a CD in the drive first, due to the fact my program does find the drive, asks for the disk, but sometimes get stuck in a loop, because it then calls the .exe on the disc to early.


Q.
So i want to know: how can i check to see if there is a Disc in the drive before executing the program that is on the disc?

I've seen that this can be acheived through calling a DLL function in Kernel32 , "GetVolumeInformation", but is
it there some other way, i m having trouble working out the parameters in
this DLL Call!

Hope someone can help!
:o

RizlaUK
01-10-2007, 10:02 AM
i beleave it is possable with the Drive.GetInformation function,

from the manual:

Returns A table containing the specified drive's information, indexed by the following keys:

Note: If the target drive is a CD-ROM drive or floppy drive, there must be a disk in the drive for this action to work. If there is no disk in the drive, nil is returned.

Label
string
The volume label of the drive. You can access this value using tb.Label.

FileSystem
string
The type of file system on the drive. For example, "FAT32", "NTFS", etc. You can access this value using tb.FileSystem.

SerialNumber
number
The drive's serial number. You can access this value using tb.SerialNumber.

DisplayName
string
The description of the drive as it appears in Windows Explorer's My Computer view. You can access this value using tb.DisplayName.


i beleave in your case you could use something like this (this is untested code, im just pointing you in the right direction)

tDriveInfo = Drive.GetInformation("your_target_drive");
if tDriveInfo.DisplayName == "your_disk_name" then
--run the file
end

mdxafx
01-10-2007, 10:48 AM
Yes, i had been looking at this method for a long time,

i think i did some early tests but didn't get the information i was
after even with using .DisplayName.

but now i have most of the registry keys in place i will
give it another shot!!

Thanks RizlaUK!

:)