Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CD Eject Button


  • Please log in to reply
3 replies to this topic
bLisTeRinG
  • Members
  • 45 posts
  • Last active: Nov 07 2012 11:15 AM
  • Joined: 15 Nov 2004
When i came across autohotkey i had all these irritations with the patchiness of windows (98 in my case). This is one of my W98 fixes. I hope it's of use to others. Feel free to hack it to bits, but be kind.

Copy & Paste the first lot of code into a text editor and save as EjectB.ahk
Save the second group of line into EjectB.ini (same folder).
Run it; it'll appear in the tray area.

;;;	Cd Eject Button v0.2 bLisTeRinG 2004

#Persistent
ver = v0.2 bLisTeRinG 2004
drIni = %A_ScriptDir%\EjectB.ini
if %0% <> 0
  {
  drive = %1%
  }
Else
  {
  iniread, drive, %drIni%, options, CdDrive,
  }
iniread, drTTC, %drIni%, options, TimeToCheck,
iniread, drTTO, %drIni%, options, TimeToOpen,
iniread, drHot, %drIni%, options, HotKey,
iniread, ico, %drIni%, options, IconFile,
iniread, ic, %drIni%, options, IconNumber,
If drTTC = , drTTC = 1000
If drTTO = , drTTO = 16000
If drHot = , drHot = n
If ico = , ico = c:\windows\system\shell32.dll
If ic = , ic = 12
If 2 NotContains Tray
  {
  Goto drEject
  }
Menu, Tray, Icon, %ico%, %ic%
Menu, Tray, nostandard
Menu, Tray, add, &Tray InOut, drEject
Menu, Tray, default, &Tray InOut
Menu, Tray, add, &Explore, drExplore
Menu, Config, add, Auto&Play, drPlay
Menu, Config, add, Auto&Open, drOpen
Menu, Config, add, &Hotkey (Win+Up), drKey
Menu, Config, add, &Refresh, drChk
Menu, Config, add, &Help, drHelp
Menu, Tray, add, Config,:Config
Menu, Tray, add, 
Menu, Tray, add, E&xit, drExit
GoSub, drChk
GoSub, drKey%drHot%
If 3 Contains Boot
  {
  Return
  }

drEject:
timmy = %A_TickCount%
EnvAdd, timmy, %drTTC%,
Drive, Eject,%drive%, 
If timmy > %A_TickCount%
  { 
  Drive, Eject,%drive%, 1
  If drOpen = 95000000
    GoSub, drRun
  } 
If 2 Contains Tray
  {
  Return
  }

drExit:
ExitApp

Return
;;;;;;;;;;;;;;;;;;;;;;;;; Routines

drChk:
RegRead, drPlay, HKCR, audiocd\shell
RegRead, drOpen, HKCU, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDriveTypeAutoRun
;msgbox, drOpen %drOpen%
If drPlay = play
  {
  Menu, Config, Check, Auto&Play
  }
Else
  {
  Menu, ConfigConfig, Uncheck, Auto&Play
  }
If drOpen = 95000000
  {
  Menu, Config, Check, Auto&Open
  }
Else
  {
  Menu, Config, Uncheck, Auto&Open
  }
Return

drExplore:
Run, %windir%\explorer.exe %drive%\
Return

drHelp:
MsgBox, `tCd Eject Button`n%a_space%         %ver%`n`nDouble click to Open/Close Cd tray.`n`nx:\EjectB.exe [y]]]`n`nx:`tThe path to EjectB.exe`ny:`tThe Cd drive (ie F:)`nTray:`tLoad a Tray Button`nBoot:`tDon't eject -just load the button
Return

drKey:
If drHot = y
  {
  GoSub, drKeyn
  }
Else
  {
  GoSub, drKeyy
  }
iniwrite, %drHot%, %drIni%, options, HotKey
Return

drKeyn:
drHot = n
Menu, Config, Uncheck, &Hotkey (Win+Up)
Hotkey, #numpadup, drEject
Hotkey, #numpadup, off
Return

drKeyy:
drHot = y
Menu, Config, Check, &Hotkey (Win+Up)
Hotkey, #numpadup, drEject
Hotkey, #numpadup, on
Return

drOpen:
If drOpen = B5000000
  {
  drOpen = 95000000
  Menu, Tray, Check, Auto&Open
  }
Else
  {
  drOpen = B5000000
  Menu, Tray, Uncheck, Auto&Open
  }
RegWrite, REG_BINARY, HKCU, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDriveTypeAutoRun, %drOpen%
Return

drPlay:
If drPlay = play
  {
  drPlay = 
  Menu, Tray, Uncheck, Auto&Play
  }
Else
  {
  drPlay = play
  Menu, Tray, Check, Auto&Play
  }
RegWrite, REG_SZ, HKCR, audiocd\shell, , %drPlay%
Return

drRun:
Sleep, %drTTO%
IfExist, %drive%\Autorun.inf
  {
  Return
  ; msgbox, Autorun.inf Found
  }
IfExist, %drive%\*.cda
  {
  Return
  }
IfExist, %drive%\*.*
  {
  GoSub, drExplore
  Return
  }
Return

; add dir-menu?

And here's the initialisation file...
[options]
TimeToCheck=1000
TimeToOpen=16000
HotKey=n
CdDrive=F:
IconFile=c:\windows\system\shell32.dll
IconNumber=12


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for sharing that. You might also find this topic of interest: Eject a CD-Rom like on Mac OS X

bLisTeRinG
  • Members
  • 45 posts
  • Last active: Nov 07 2012 11:15 AM
  • Joined: 15 Nov 2004
The mac os-like cd eject doesn't work at all unless you're using WinXp.
and anyway the new CdEject button gives access to autoopen behaviour, multiple cd drives, can be used stand-alone, or loaded in the tray.

Also, it allows for a hot-key and ought work in all flavours (get back to me on that - i only have my W98e)

To load CdEject button:

EjectB F:[ Tray[ Boot]]

The Boot option is for when loading at startup.

Sam Bo
  • Members
  • 264 posts
  • Last active: Jun 13 2018 04:30 AM
  • Joined: 03 Dec 2011
:mrgreen: :mrgreen: :mrgreen: :mrgreen:
I have this code for watch if the CD tray is out.

NumLock::
Drive, Eject,,  ; ------------ EXPULSE
SplashImage,, m2 x550 y430 fs40 ctSilver cwBlack, The CD tray is OUT, , ,Arial
If ErrorLevel = 0 ; ---- just in case of success  OR -------- Close the drive if ejecting fails ????
{
   If A_TimeSinceThisHotkey < 1000
   {
Drive, Eject,, 1  ; ------- RETRACT
SplashImage,,x550 y430 b fs40 ctSilver cwBlack, The CD is INSIDE, , ,Arial
sleep, 1000
SplashImage, Off
  return
   }
}


Drive, Eject,%drive%, 1
If drOpen = 95000000


What I ned is some to detect if the CD tray is out. THANKS.