I want to thanks MHz for the great example using Switch...Case...EndSwitch & using Command Line Parameters in CDROM script. It actually inspires me to write my own version of ejecting/closing the DVDtray.
My idea is to place the menu only on My Computer -> Context menu -> Open ($Driveletter) & Eject ($driveletter)
I'm stuck in getting it to display the helpfile when double click the complied exe (DVDTray.exe) w/o any parameters.
(I understand help file is display via cmdline using DVDtray /?)
Also I base the drive letter thru 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup', 'Installation Sources'
as I think it represent the actual drive letter since it is use for Xp setup installation, not virtual drive letter. (I only have I drive). Or is there a better regkey to read off the drive letter? Advice appreciated.
[attachment=24459:DVDTray.au3]
#NoTrayIcon
$DVDLetter = StringMid(RegRead ('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup', 'Installation Sources'),1,2)
$ValidiateDriveLetter=StringRegExp ($DVDLetter,"([A-Z]:)",0);0 = Returns 1 (matched) or 0 (no match)
If $ValidiateDriveLetter=0 then;code 0 means invalid drive letter
Msgbox (48,"Invalid Drive letter, Exit !",$DVDLetter)
Exit
endif
If $CMDLINE[0] then
Switch $CMDLINE[1]
Case 'help', '/?', '-?', '/help'
Call ("_DisplayHELP")
Case 'open'
ToolTip ( "Ejecting "&$DVDLetter&" tray...", @DesktopWidth/2 , @DesktopHeight/2 , "DVDTray" , 0,1 )
CDTray($DVDLetter, 'open')
Case 'close'
ToolTip ( "Closing "&$DVDLetter&" tray...", @DesktopWidth/2 , @DesktopHeight/2 , "DVDTray" , 0,1 )
CDTray($DVDLetter, 'closed')
EndSwitch
Endif
Func _DisplayHELP()
$GetOSVer=@OSVersion
If $GetOSVer =StringCompare ($GetOSVer,"WIN_VISTA",1) then $OSmsgText="Computer"
If $GetOSVer =StringCompare ($GetOSVer,"WIN_2000",1) then $OSmsgText="My Computer"
If $GetOSVer =StringCompare ($GetOSVer,"WIN_XP",1) then $OSmsgText="My Computer"
MsgBox(0x40000, Default, 'DVDTray Cmd Syntax are:' & @CRLF & _
'Open ('&$DVDLetter &')'& @CRLF & _
'Close ('&$DVDLetter&')' &@CRLF&@CRLF & _
'*() Drive letter is automatically assigned.'&@CRLF & _
'It will not take another drive letter'&@CRLF & _
'such as DVDTray open J:'& @CRLF&@CRLF & _
'Menu appears in Context Menu of '&$OSmsgText&@CRLF&@CRLF & _
'This program can be uninstall in Add/Remove Programs -->DVDTray'); show help & info
EndFunc
==Edit==
Sorry. My actual drive is
$DVDLetter = StringMid(RegRead ('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup', 'Installation Sources'),1,2)
Post the wrong drive as it was just to test my script. I have amended in the codebox to reflect this change but not in the attachment.
There are 3 files that I built, 1) Installer, 2)DVDtray & 3)uninstaller
I just post the DVDTray.au3 code part as I'm loss how to get it display the help info by doubling clicking DVDtray.exe
This post has been edited by Geej: 29 December 2008 - 06:36 PM