View Full Version : Help: How to Eject CDROM after Application Exit
morci
06-04-2009, 07:15 PM
Hi all,
I have my application running and working but I cant seem to get the variable Drive.Eject(_SourceDrive) working.
I get windows error 'Windows - No Disk : There is no disk in the drive. Please insert a disk into drive F:. '
Where do i put this variable ? I have tried this in:
1 Project - Actions - On Shutdown = fails with windows error
2 In my steps below - fails, windows error
2 Page - Properties - Script - On Close = fails with windows error
Can anyone help me please?
My Project
-- Check to see if the Scripts folder exists in C:\.
does_exist = Folder.DoesExist("C:\\Scripts");
-- Display a dialog telling the user whether or not the folder exists.
if does_exist then
Dialog.Message("Notice", "The folder C:\\Scripts already exists in your system. This update will terminate", MB_OK, MB_ICONINFORMATION);
Application.Exit(0);
else
Folder.Create("C:\\Scripts")
Dialog.TimedMessage("Please Wait...", "Files will be copied to your pc, this may time a few minutes...", 5000, MB_ICONINFORMATION);
StatusDlg.Show();
File.Copy(_SourceFolder .. "\\Scripts\\*.*", "C:\\Scripts\\", true, true, false, true, nil);
StatusDlg.Hide();
result = Dialog.Message("Finished", "All tasks have been completed successfully. This program will close and the CDROM will be ejected.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit(0);
end
MicroByte
06-05-2009, 04:41 AM
the problem is that the exe file is still in use when the drive is ejected, thus causing the error, the same thing happens if you eject the drive manualy
only thing i can think of right now is setup a small exe or .bat file on the system to eject the drive after the app exists, but there is no way to eject the drive the app is running from without generating a error (that i know of)
Imagine Programming
06-05-2009, 05:33 AM
You could also copy the application to _TempFolder, do the tasks required and eject the CD. You could even delete the application from _TempFolder by writing a batch file that deletes it.
MicroByte
06-05-2009, 07:22 AM
as long as you physically copy and run the file from the temp folder, launching a web exe will not work as the shell remains in memory from the disk while the app is running from the temp folder, the runtime does this so it can delete the temp folder after use but its easy enough to replicate with a bat file (remember to delay it!)
Imagine Programming
06-05-2009, 08:10 AM
I guess your way is better, but how can you eject a cd drive using batch?
MicroByte
06-05-2009, 08:33 AM
you dont, you make the exe in the temp folder eject the drive and then run the .bat to delete the temp folder with enough delay to ensure the application is cleared from memory
Imagine Programming
06-05-2009, 08:46 AM
you dont, you make the exe in the temp folder eject the drive and then run the .bat to delete the temp folder with enough delay to ensure the application is cleared from memory
Lol now i get it, i didn't read well ;p
morci
06-07-2009, 03:40 AM
Hi all,
So if i read this right - after autoplay finishes, there is NO way to Eject the CD?
From my script im only copying files from CDROM to C:\Scripts then I want to close Autoplay and Eject CDROM = Impossible to do without copying everything to C:\Temp first then run from C:\Temp then eject and delete everything from C:\Temp
This sounds so silly that Autoplay cant do this -I used to do this via a DLL in Autoplay 5.0 (and dont want to use that) but since 7.5 its built in thought it might be easier - but i guess i will just show a message box that says 'Thanks - things done, please eject CD when program closes'.
Oh well - and I thougth 7.5 was much beta than 5.0
Thanks to all that replied.
Morci
MicroByte
06-07-2009, 09:35 AM
well i cant speak for v5 as i never used it, but i can state that this would still happen in any language, if the cdrom is in use by a active application and you eject it you will receive a error
leebos
06-08-2009, 09:48 AM
Try this code in the projects On Shutdown action.
Lee
-- Get the type of the drive where the application is running from.
drive_type = Drive.GetType(_SourceDrive);
-- If the drive type is a CD/DVD ROM drive, eject it.
if (drive_type == DRIVE_CDROM) then
result = Dialog.Message("Notice", "Do You want to Eject the CD?.", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
if result == 6 then
instances_of_file = 0;
file_to_check_for = "autorun.exe"; --have all lowercase
processes = System.EnumerateProcesses();
for j, file_path in processes do
file = String.SplitPath(file_path);
if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
System.TerminateProcess(j);
end
Drive.Eject(_SourceDrive);
end
end
end
morci
06-10-2009, 12:01 AM
Hi all,
Thanks for all your comments but i have solved the eject CD issue:
1 autoplay.exe runs from CDROM
2 when you close autoplay.exe - you want to eject the CD automatically
Solution: :)
---------
1 Add this single line before you exit the application
DLLResult = DLL.CallFunction("winmm.dll", "mciSendStringA", "\"Set CDAudio Door Open\",0,0,0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
Application.Exit(0);
So, in your project, add the DLL result line just before you exit the application, this will EJECT the CDROM.
I have tested this in XP, Win2k, W2k3 and it they work with no issue.
Hope this helps everyone
Morci :)
MicroByte
06-10-2009, 02:27 AM
nice workaround :yes
Imagine Programming
06-10-2009, 04:38 AM
Agreed, well found.:yes
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.