Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2002
    Posts
    17

    Huh? Help: How to Eject CDROM after Application Exit

    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

  2. #2
    Join Date
    Apr 2009
    Posts
    277
    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)

  3. #3
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    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.
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  4. #4
    Join Date
    Apr 2009
    Posts
    277
    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!)

  5. #5
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    I guess your way is better, but how can you eject a cd drive using batch?
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  6. #6
    Join Date
    Apr 2009
    Posts
    277
    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

  7. #7
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Quote Originally Posted by MicroByte View Post
    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
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  8. #8
    Join Date
    Nov 2002
    Posts
    17
    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

  9. #9
    Join Date
    Apr 2009
    Posts
    277
    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

  10. #10
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    113
    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

  11. #11
    Join Date
    Nov 2002
    Posts
    17

    Smile Eject CDROM after autoplay.exe closes - SOLVED!

    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

  12. #12
    Join Date
    Apr 2009
    Posts
    277
    nice workaround

  13. #13
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Agreed, well found.
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts