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.

Re: Is it possible to have my CD-Rom load via a script. (Close the by mr_unreliable

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.
>

uh-oh, correction / clarification by mr_unreliable

mr_unreliable
Thu Aug 30 08:06:24 PDT 2007

Delete this:
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.

Replace with this:
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. And, when you want to close
the cd drawer, what do you do? You push the _SAME_ eject
button. In other words, you use the same button to open
as to close.

as ever, jw


Re: uh-oh, correction / clarification by iridius

iridius
Thu Aug 30 12:55:24 PDT 2007

On Aug 30, 11:06 am, mr_unreliable
<kindlyReplyToNewsgr...@notmail.com> wrote:
> Delete this:
> 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.
>
> Replace with this:
> 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. And, when you want to close
> the cd drawer, what do you do? You push the _SAME_ eject
> button. In other words, you use the same button to open
> as to close.
>
> as ever, jw

I must admit you lost me, as I am new to VBS....
If I need to do the same thing, why can't I just copy the last part of
the script to to beginning.

CreateObject("Shell.Application").Namespace(17).ParseName("K:
\").InvokeVerb("E&ject")

?

If I wanted to do what you originally suggested, could you break it
down to me, how do I integrate that into my already existing .vbs file?


Re: Is it possible to have my CD-Rom load via a script. (Close the CD Tray) by Michael

Michael
Sat Sep 01 05:19:09 PDT 2007

On Wed, 29 Aug 2007 09:03:27 -0700, iridius wrote in
microsoft.public.scripting.vbscript:

[snip]
>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.

You could launch Dave Navarro's program:

EJECT v2.02 - Removable Media Eject/Load
Copyright (c) 1998-2001 WebGeek, Inc. (dave@basicguru.com)

Usage: eject drive [/l]

/l load (does not work with all CDROM drives)

Works here. See: <http://www.powerbasic.com/files/pub/AllFiles.asp> or
directly: <http://www.powerbasic.com/files/pub/pbwin/tools/Eject.zip>.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Re: Is it possible to have my CD-Rom load via a script. (Close the CD Tray) by iridius

iridius
Tue Sep 11 12:23:39 PDT 2007

On Sep 1, 8:19 am, Michael Bednarek
<mbATmbednarek....@BLACKHOLESPAM.NET> wrote:
> On Wed, 29 Aug 2007 09:03:27 -0700, iridius wrote in
> microsoft.public.scripting.vbscript:
>
> [snip]
>
> >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.
>
> You could launch Dave Navarro's program:
>
> EJECT v2.02 - Removable Media Eject/Load
> Copyright (c) 1998-2001 WebGeek, Inc. (d...@basicguru.com)
>
> Usage: eject drive [/l]
>
> /l load (does not work with all CDROM drives)
>
> Works here. See: <http://www.powerbasic.com/files/pub/AllFiles.asp> or
> directly: <http://www.powerbasic.com/files/pub/pbwin/tools/Eject.zip>.
>
> --
> Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Yep, that seems to be the answer, I'm surprised there's no such built
in functionality, but I ended up with the following script that
works. Thanks a ton.

Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.Run "%COMSPEC% /c c:\eject\eject.exe k: /l"

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "K:\*.*" , "I:\" , OverwriteExisting

CreateObject("Shell.Application").Namespace(17).ParseName("K:
\").InvokeVerb("E&ject")

Wscript.Echo "Processing information. This might take several
minutes."

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set colServices = objWMIService.ExecQuery("Select * from
Win32_Service")

For Each objService in colServices
Wscript.StdOut.Write(".")
Next

Wscript.StdOut.WriteLine
Wscript.Echo "Service information processed."



Re: Is it possible to have my CD-Rom load via a script. (Close the CD Tray) by noone

noone
Sun Sep 30 09:34:22 PDT 2007

Il giorno Tue, 11 Sep 2007 19:23:39 -0000, iridius <iridius7@gmail.com> ha scritto:
>Yep, that seems to be the answer, I'm surprised there's no such built
>in functionality, but I ended up with the following script that
>works. Thanks a ton.

Mediaplayer has an "eject" method.
Set oCD = CreateObject("WMPlayer.OCX.7").cdromCollection.getByDriveSpecifier("e:")
oCD.Eject


' *****************************************************
' eject.vbs
' Cenati Giovanni - http://digilander.libero.it/Cenati
' Codice liberamente utilizzabile citando il sito
' Questo script trova tutti i lettori cd collegati
' al pc e per ciascuno di essi chiede se si vuole
' aprire il cassetto e poi richiuderlo.
' *****************************************************
Set oWMP = CreateObject("WMPlayer.OCX.7")

Set colCDROMs = oWMP.cdromCollection
'Chiede a MediaPlayer l'elenco dei drive cdrom
'oppure posso specificarne la lettera come qui sotto.
'Set oCD = oWMP.cdromCollection.getByDriveSpecifier("e:")
'oCD.Eject

if colCDROMs.Count >= 1 then
for i=0 to colCDROMs.Count - 1
'Chiede a MediaPlayer la lettera dell'i-esimo drive cdrom
strDrive= oWMP.cdromCollection.item(i).driveSpecifier
strQuestion = "Espellere drive " & strDrive & "?"
answer= msgbox (strQuestion, vbOKCancel)
if answer= vbOK then
colCDROMs.Item(i).Eject
strQuestion = "Richiudere drive " & strDrive & "?"
answer= msgbox (strQuestion, vbOKCancel)
if answer= vbOK then colCDROMs.Item(i).Eject
end if
next 'drive nella collezione dei drive CDROM
end if
wscript.quit


--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--