Eject CD/DVD tray--simpe java script

Discussion in 'Scripting' started by stayboogy, May 15, 2011.

  1. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    #1 stayboogy, May 15, 2011
    Last edited: May 15, 2011
    got a cd/dvd tray that hates it when you use the button and won't respond like it should ALL THE TIME (like me, lol)--try this

    #open notepad, copy and paste, replace drive letter with, you guessed it, the drive letter ie. C D E F etc.#

    Drive = "drive letter:\\"
    sa = new ActiveXObject("Shell.Application")
    fl = sa.NameSpace(Drive).Self
    fl.InvokeVerb("E&ject")

    #save as "whatever.js" and it doesn't have to be in the root dir or anything, save it anywhere you like and can find it#

    create a shortcut and place it on your desktop, double click and viola.
     
  2. zahnoo

    zahnoo MDL Senior Member

    Feb 2, 2011
    387
    35
    10
    I did as instructed but nothing happens when I run the script ... absolutely nothing either good or bad. If I remove the quotes from line 1 I get an error message saying a ";" is expected in place of the ":" at position 10. Same results both with and without the "\\".

    Being unfamiliar with Javascript, most likely I'm not editing as you want it done.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,589
    340
    Me also... nothing happen... o_O
     
  4. jayblok

    jayblok MDL Guru

    Dec 26, 2010
    3,199
    2,579
    120
    ??did not work for me,what happened
     
  5. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    #5 stayboogy, May 15, 2011
    Last edited: May 15, 2011
    (OP)
    surely you guys are joking???

    1) did you replace the words drive letter on the first line with the actual letter of the drive that you are wanting to eject, which should only be cd/dvd drives?

    zahnoo,
    2) do not remove any quotes either, and it has to have these two \\ after the drive letter and colon

    3) do you have the latest java installed?

    4) did you save it as .js ?

    5) do you have a virtual drive setup, such as Daemon tools or something like it? make sure you are using the physical drive's letter and not the virtual drive's letter (I had a similar issue the first time i tried it a couple of years ago because i put the wrong drive letter on the first line) Daemon tools often lists its virtual drive before the physical drive in "my computer" so check that...

    i'm running XP but i do not see why this wouldn't work with newer OSes.

    here is what my script looks like exactly, which works perfectly every time i double click:

    Drive = "H:\\"
    sa = new ActiveXObject("Shell.Application")
    fl = sa.NameSpace(Drive).Self
    fl.InvokeVerb("E&ject")


    "H:\\" is my cd/dvd drive--other examples: "C:\\" "D:\\" "E:\\" "F:\\" "G:\\" etc. etc.

    if it's not working after checking all these things, then i'm not sure why it doesn't work for you because i have no issues with it and i use it on a daily basis...
     
  6. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,589
    340
    I did exactly what u said... still no result!! Have the latest Java runtime installed :confused:
     
  7. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    are you running vista by chance? i have heard of problems with vista and this script...

    otherwise i do not know??? there must be something amiss somewhere.
     
  8. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,589
    340
    Noop, Windows 7 Ultimte...
     
  9. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    idk, Tito, does it give you any errors?
     
  10. zahnoo

    zahnoo MDL Senior Member

    Feb 2, 2011
    387
    35
    10
    Same for me still ... nothing. I have the latest Java runtime and Windows 7 Home Premium SP1
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    #11 stayboogy, May 15, 2011
    Last edited: May 15, 2011
    (OP)
    i surely wouldn't post something that didn't work if i thought that was the case though, guys, so i do apologize, but as i said before it works perfectly for me

    idk, really, but i can't find any reason why it will not work either. there are no syntax errors or anything, and i assure you i have no problems whatsoever, it works for me all the time and my pc isn't the most perfect but i don't have any java, active x, etc errors, so, idk...

    i tried running this on a vista machine which it didn't work, saying sa was not defined on line 3 even though it clearly is...

    i'm going to say that this clearly doesn't work with anything other than XP @ the moment and probably has something to do with the way the embedded security system works in Vista, 7, etc. which i had no idea would be the case and i can't really figure why either. could be an active X problem on you guys' machines, though i'm not quite sure it would be causing it not to work.

    someone running XP should try this or try it in your VM that is running XP; or you guys running 7 try running in XP compatibility mode and see if that works for you that way

    this is a download link to my script from my pc, there are no viruses i assure you as i've already posted the txt above; just edit H to your drive letter in the text and run

    here's the scan link: no maleware, virus, etc.
    http://virscan.org/report/4232108e6563452d6e081c215231fdc3.html

    http://www.mediafire.com/?tw2ipc314gtbjvc
     
  12. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    just a follow up to this:

    this does not work in Windows 7 @ all, nor does it work in Windows Vista--and i still cannot figure out why. I think it has something to do with the "eject" context not being tied to activeX controls, but i'm not completely sure.

    But I have tested this on a few other machines running various other versions of XP and this script worked just fine as long as ActiveX and Java are installed and the proper letter is used for the drive.
     
  13. searchengine

    searchengine Guest

    Nircmd available x32|64bit, works well for Eject|Close CD|DVD Tray functions.

    I added to right-click [​IMG]
     
  14. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    846
    215
    30
    actually it wasn't copied from "there"

    little trick i picked up from a nerd friend in fact.

    just now saw your post, but don't accuse me of something that you don't have the facts about...
     
  15. acozart

    acozart MDL Novice

    Mar 14, 2010
    17
    1
    0
    eject cd

    here is a vbs scripe that I found which will eject a cd or dvd drive
    just past in in a txt file and rename the extension to vbs

    Dim ts
    Dim strDriveLetter
    Dim intDriveLetter
    Dim fs 'As Scripting.FileSystemObject
    Const CDROM = 4
    On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    strDriveLetter = ""
    For intDriveLetter = Asc("A") To Asc("Z")
    Err.Clear
    If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
    If Err.Number = 0 Then
    strDriveLetter = Chr(intDriveLetter)
    Exit For
    End If
    End If
    Next
    MSGBOX "YOUR CD IS: " & strDriveLetter,VBOKONLY + 48,"CDROM=> " & strDriveLetter
    Set oWMP = CreateObject("WMPlayer.OCX.7" )
    Set colCDROMs = oWMP.cdromCollection
    For d = 0 to colCDROMs.Count - 1
    colCDROMs.Item(d).Eject
    Next 'null
    'A1= msgbox ("Press key To Close Cd" & vbcrlf &_
    ' " The Cd Will Close", 0 + 64, "Open Close Cd Tray")
    ' For d = 0 to colCDROMs.Count 1
    ' colCDROMs.Item(0).Eject
    'Next 'null

    set owmp = nothing
    set colCDROMs = nothing
    wscript.quit
     
  16. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #17 Dos_Probie, Sep 14, 2012
    Last edited by a moderator: Apr 20, 2017
    Nada..Nothing..No Mas.. let's be Democratic and take a vote.. All in Favor say Aye, all opposed Nay..
    I think the Nays win on this one..:worthy:
    Personally I like this Working .vbs script that I use for my temperamental lap dvd drive and it never let's me down!

    Code:
    'Auto Eject DVD Tray'
    
    For Each d in CreateObject("Scripting.FileSystemObject").Drives
    CreateObject("Shell.Application").Namespace(17).ParseName("E:\").InvokeVerb("Eject")
    Next
     
  17. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    60
    #18 Muerto, Sep 14, 2012
    Last edited: Aug 22, 2021
    ...
     
  18. nleknh

    nleknh MDL Novice

    Apr 24, 2011
    11
    1
    0
    Form me not working on Windows 8 Enterprise 64 bit.
     
  19. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #20 Dos_Probie, Nov 28, 2012
    Last edited by a moderator: Apr 20, 2017
    Here is a Tested solution for Vista and Windows 7 and now 8 that Works!..Will add "Eject DVD-RW Tray" with icon to your
    desktop right-click context menu.. (see bottom image)
    1. Google and Download Nircmd either 32 or 64-bit as needed.
    2. Then take the Eject.bat and nircmd.exe file and put then in your System32 folder.
    3. Now merge the .reg file to the registry and your good to go!
    P.S. I chose Nircmd over a .vbs eject script because of false-postive with
    Windows saying the .vbs script was a joke eject virus.
    Code:
    @ echo off
    ::=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    :: No more fumbling around trying to push
    :: that effin' laptop tray button again!
    :: Designed for Windows Vista, 7 and 8.
    ::=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    :: Eject.bat
    ::• Scan-Detect-Go To DVD Drive Letter •
    ::==> CODE STARTS <==
    cd %~dp0
    for %%a in (D E F G H I J) do (
    fsutil.exe fsinfo drivetype %%a:|find "CD-ROM">nul&&set dvd=%%a:&&goto :%%a
    )
    :: DRIVES
    :D
    start "" nircmd.exe cdrom open d: 
    goto :eof
    :E
    start "" nircmd.exe cdrom open e: 
    goto :eof
    :F
    start "" nircmd.exe cdrom open f: 
    goto :eof
    :G
    start "" nircmd.exe cdrom open g: 
    goto :eof
    :H
    start "" nircmd.exe cdrom open h: 
    goto :eof
    :I
    start "" nircmd.exe cdrom open i: 
    goto :eof
    :J
    start "" nircmd.exe cdrom open j: 
    goto :eof
    :eof
    exit
    ::==> CODE ENDS <==
    ::rev. 11.28.12_Dos Probie ö¿ö
    Code:
    Windows Registry Editor Version 5.00
    ;Eject.reg
    ; Add "Eject DVD-RW Tray" to right click menu
     [HKEY_CLASSES_ROOT\Directory\Background\shell\Eject DVD-RW Tray]
     "icon"="shell32.dll,-165"
     "Position"="Middle"
     [HKEY_CLASSES_ROOT\Directory\Background\shell\Eject DVD-RW Tray\command]
     @="Eject.bat"
    
    Eject.jpg