Cd-rom Open/close

Wasn't quite sure where to put this so if the Mods want to move it feel free.

Just browsing VB sites and found a function that ejects the cdrom of your choice using the WMP SDK.

I just thought I'd incorporate it into a simple script file so that it can be sued/linked from the dock.

Anyway here it is:

Option Explicit
On Error Resume Next

Dim WshShell, chkOpen, RegEntry, RegCheck, ErrNum, wmp, cdroms

Set WshShell = WScript.CreateObject("WScript.Shell")
Set wmp = CreateObject("WMPlayer.OCX.7")
Set cdroms = wmp.cdromCollection

const Drive = "0"

RegEntry = "HKCU\Software\CDTray\"

RegCheck = WSHShell.RegRead (RegEntry)
ErrNum = Err.Number

if ErrNum <> 0 then
WshShell.RegWrite "HKCU\Software\CDTray\", 0 ,"REG_DWORD"
WshShell.RegWrite "HKCU\Software\CDTray\OpenClose", "1"
End If


chkOpen = WshShell.RegRead ("HKCU\Software\CDTray\OpenClose")

If chkOpen = "1" Then
If cdroms.Count >= 1 then
 cdroms.Item(Drive).Eject
End If
WshShell.RegWrite "HKCU\Software\CDTray\OpenClose", "0"
Else
If cdroms.Count >= 1 then
 cdroms.Item(Drive).Eject
 cdroms.Item(Drive).Eject
WshShell.RegWrite "HKCU\Software\CDTray\OpenClose", "1"
End If
End If

WshShell.Run "Taskkill.exe /F /IM WScript.exe", 0, TRUE

Set WshShell = vbnull
Set wmp = vbnull
Set cdroms = vbnull

Just copy and paste into a vbs file and then drag it to your dock. ;)

By the way, you can select which drive you want it to link to by changing the constant 'Drive', where o is your first Drive and 1 would be your second drive etc.

Hope someone finds a use for it! :D

#79301

Great, Thanx!! works perfectly, i jst had to set up norton to allow the activity... ;)

#79302

can I use this as an argument with the Pogz's bezelizer?

I'm not an expertise....

#79306

Originally posted by mefistus@Nov 17 2003, 03:00 PM

can I use this as an argument with the Pogz's bezelizer?

I'm not an expertise....

Use it however you like.

Slight problem I've just encountered though with memory management, for some reason it doesn't unload from memory like other scripts i've created :blink: I dunno what the exact problem is but you get loads of 'wscript.exe' instances in your task list!

For now I'm going to use the taskkill to terminate the script once finished so please check the original post and update your script.

#79311

ok

by the way....do you use the bezelizer?

#79314

"mr. hankey" yeah i had not noticed that, i had like 10 of those @ 8mb + each!!

#79318

I don't see any instance of th wscript.exe in the process viewer.... :blink:

#79319