mr_unreliable
Wed Aug 29 15:26:05 CDT 2007
hi iridius,
Here is an "epiphany moment". When you want to open your
(audio) cd drawer at home, what do you do? You push eject,
or at least that's what I do. In other words, you use the
same button to open as to close.
Now back to scripting. The following script, posted back
in 2003 by Don Grover and Robert Cohen works "both ways".
Run it once, and the drawer opens. Run it again, and the
drawer closes.
--- <snip> ---
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
End If
--- </snip> ---
I must say, this worked for me back in 2003, but doesn't
work today. But then, my system has been a little flaky
lately.
There is another way, if you are willing to call the
system api's from script (something frowned upon by
professional scripters).
--- <snip> ---
' open/close cd-rom drawer (using api calls), jw 22Nov00
' (several examples of this found on www.codehound.com/vb/)
Option Explicit
Dim oATO ' as object (api toolkit)
Dim nRtn ' as long
'
Const sMBCaption = " < test open/close cd-rom drawer > "
' ------------------------------------------------
On Error Resume Next ' instantiate "wshAPIToolkitObject" ocx...
Set oATO = WScript.CreateObject("wshAPIToolkitObject.ucATO")
BugAssert (err.number = 0), "This script requires wshAPIToolkitObject "
On Error goto 0 ' turn off error checking...
' warn about opening the cd-rom drawer...
nRtn = MsgBox("warning, this script will OPEN your cd-rom drawer " &
vbCrLf & vbCrLf _
& " ..click ok to make it happen", vbExclamation, sMBCaption)
nRtn = oATO.CallAPI("WINMM.DLL", "mciSendStringA", "Set CDAudio Door
Open", 0, 0, 0)
' wait-a-bit, to allow drawer to open...
WScript.Sleep 500
' warn about opening the cd-rom drawer...
nRtn = MsgBox("warning, this script will CLOSE your cd-rom drawer " &
vbCrLf & vbCrLf _
& " ..click ok to make it happen", vbExclamation, sMBCaption)
nRtn = oATO.CallAPI("WINMM.DLL", "mciSendStringA", "Set CDAudio door
closed", 0, 0, 0)
Set oATO = nothing ' clean up...
WScript.Quit
' ================================================
' === SUBROUTINES FOLLOW =========================
' ================================================
' --- BUGASSERT (yes, it's for debugging) --------
Sub BugAssert (bTest, sErrMsg)
' BugAssert is a Bruce McKinney creation.
' It is used to test for intermediate results...
if bTest then Exit Sub
MsgBox "Error Detected by BugAssert: " & vbCr & vbCr & sErrMsg, _
vbCritical, " << BugAssert FAILED >> "
WScript.Quit
End Sub
--- </snip> ---
I can testify that this latter (api way) script still works.
Of course, this (latter) script uses the rare and ellusive
wshAPIToolkit control for calling api's, which is virtually
impossible to find these days. However DynaWrap is still
around.
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
--- <DynaWrap Boilerplate> ---
It is possible to declare-and-call an api from script,
but you must use a third-party control to do so,
or else write one yourself.
It has already been correctly pointed out that there
is no api-capability in "pure" script.
If you are willing to use a third-party control, then
one such control, called "DynaWrap", can be found on
Guenter Born's website (note: Guenter refers to it as
"DynaCall"). Here is the link to it:
http://people.freenet.de/gborn/WSHBazaar/WSHDynaCall.htm
On that page you will find a download for the control,
plus some code samples.
Note: you may find additional sample code by searching
the archives of the wsh and vbscript ng's.
Note also: DynaWrap does have its limitations. There are
certain things it can't do. For example, you can't call
api's which take typedefs as parameters, and you can't call
api's "by ordinal". But it will work for most of the
"usual suspects".
And finally, DynaWrap doesn't work entirely as advertised.
For example, it is supposed to allow for the declaration of
several api definitions in one instance of itself. I could
never get that to work (in win9x). You will need a new
instance of DynaWrap for every api, or else re-instantiate
the object for every api. Someday I'm going to learn enough
c++ to fix that...
--- </DynaWrap Boilerplate> ---
iridius wrote:
> I have the following script, that is awesome thanks to this group:
>
> ****************************************************************************
> Const FOF_CREATEPROGRESSDLG = &H0&
>
>
> Set objShell = CreateObject("Shell.Application")
> Set objFolder = objShell.NameSpace("I:\")
>
>
> objFolder.CopyHere "K:\*.*", FOF_CREATEPROGRESSDLG
>
> CreateObject("Shell.Application").Namespace(17).ParseName("K:
> \").InvokeVerb("E&ject")
> ****************************************************************************
>
> The only thing I would like it to do in addition is to load the CD I
> place in the tray, so I don't have to push the tray or button on the
> CD drive itself, is this possible via a script? Any ideas.
>